On this page:

12 Conversion to Expectations


(->expectation v)  expectation?

  v : any/c
Returns an expectation constructed by converting v to an expectation. Expectation conversion occurs via the following process:

This process roughly means that v is converted to an expectation that checks that its input is equal? to v, unless v is a container with expectations inside it. For example, note the difference between the following two expectations:

> (expect! (list 1 2) (->expectation (list 1 expect-any)))
> (expect! (list 1 2) (expect-equal? (list 1 expect-any)))

expected a different value

  subject: '(1 2)

  in: item at position 1

  expected: equal? to #<expectation:any>

  actual: 2

So ->expectation can be thought of a variant of expect-equal? that allows specifying that sub-structures of the value should match some expectation instead of merely being equal? to an expected value.

WARNING: Not all built-in Racket collection types are supported, and there is no way for custom data types to cooperate with ->expectation. These limitations may be addressed by future versions of this library.