The expect
function is used every time you want to test a value.
You will rarely call expect
by itself.
The value to apply matchers against.
Matches any array made up entirely of elements in the provided array.
You can use it inside toEqual
or toBeCalledWith
instead of a literal value.
Optionally, you can provide a type for the elements via a generic.
Useful when comparing floating point numbers in object properties or array item.
If you need to compare a number, use .toBeCloseTo
instead.
The optional numDigits
argument limits the number of digits to check after the decimal point.
For the default value 2, the test criterion is Math.abs(expected - received) < 0.005
(that is, 10 ** -2 / 2
).
Optional
numDigits: numberYou can use expect.extend
to add your own matchers to Jest.
Matches any object that recursively matches the provided keys. This is often handy in conjunction with other asymmetric matchers.
Optionally, you can provide a type for the object via a generic. This ensures that the object contains the desired structure.
The
expect
function is used every time you want to test a value. You will rarely callexpect
by itself.