Ensure that the last call to a mock function has returned a specified value.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Ensure that a mock function is called with specific arguments on an Nth call.
Optionally, you can provide a type for the expected arguments via a generic. Note that the type must be either an array or a tuple.
Ensure that the nth call to a mock function has returned a specified value.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Checks that a value is what you expect. It uses Object.is
to check strict equality.
Don't use toBe
with floating-point numbers.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Ensures that a mock function is called.
Ensures that a mock function is called an exact number of times.
Ensure that a mock function is called with specific arguments.
Optionally, you can provide a type for the expected arguments via a generic. Note that the type must be either an array or a tuple.
Using exact equality with floating point numbers is a bad idea. Rounding means that intuitive things fail. The default for numDigits is 2.
Ensure that a variable is not undefined.
When you don't care what a value is, you just want to ensure a value is false in a boolean context.
For comparing floating point numbers.
For comparing floating point numbers.
Ensure that an object is an instance of a class.
This matcher uses instanceof
underneath.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
For comparing floating point numbers.
For comparing floating point numbers.
Used to check that a variable is NaN.
This is the same as .toBe(null)
but the error messages are a bit nicer.
So use .toBeNull()
when you want to check that something is null.
Use when you don't care what a value is, you just want to ensure a value
is true in a boolean context. In JavaScript, there are six falsy values:
false
, 0
, ''
, null
, undefined
, and NaN
. Everything else is truthy.
Used to check that a variable is undefined.
Used when you want to check that an item is in a list.
For testing the items in the list, this uses ===
, a strict equality check.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Used when you want to check that an item is in a list. For testing the items in the list, this matcher recursively checks the equality of all fields, rather than checking for object identity.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Used when you want to check that two objects have the same value. This matcher recursively checks the equality of all fields, rather than checking for object identity.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Ensures that a mock function is called.
Ensures that a mock function is called an exact number of times.
Ensure that a mock function is called with specific arguments.
Optionally, you can provide a type for the expected arguments via a generic. Note that the type must be either an array or a tuple.
If you have a mock function, you can use .toHaveBeenLastCalledWith
to test what arguments it was last called with.
Optionally, you can provide a type for the expected arguments via a generic. Note that the type must be either an array or a tuple.
Ensure that a mock function is called with specific arguments on an Nth call.
Optionally, you can provide a type for the expected arguments via a generic. Note that the type must be either an array or a tuple.
Use to test the specific value that a mock function last returned. If the last call to the mock function threw an error, then this matcher will fail no matter what value you provided as the expected return value.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Used to check that an object has a .length
property
and it is set to a certain numeric value.
Use to test the specific value that a mock function returned for the nth call. If the nth call to the mock function threw an error, then this matcher will fail no matter what value you provided as the expected return value.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Use to check if property at provided reference keyPath exists for an object. For checking deeply nested properties in an object you may use dot notation or an array containing the keyPath for deep references.
Optionally, you can provide a value to check if it's equal to the value present at keyPath
on the target object. This matcher uses 'deep equality' (like toEqual()
) and recursively checks
the equality of all fields.
Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times. Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
Use to ensure that a mock function returned a specific value.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Check that a string matches a regular expression.
This ensures that a value matches the most recent snapshot with property matchers. Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically. Check out the Snapshot Testing guide for more information.
This ensures that a value matches the most recent snapshot with property matchers. Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically. Check out the Snapshot Testing guide for more information.
Used to check that a JavaScript object matches a subset of the properties of an object
Optionally, you can provide an object to use as Generic type for the expected value. This ensures that the matching object matches the structure of the provided object-like type.
This ensures that a value matches the most recent snapshot with property matchers. Check out the Snapshot Testing guide for more information.
This ensures that a value matches the most recent snapshot. Check out the Snapshot Testing guide for more information.
Ensure that a mock function has returned (as opposed to thrown) at least once.
Ensure that a mock function has returned (as opposed to thrown) a specified number of times.
Ensure that a mock function has returned a specified value at least once.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Use to test that objects have the same types as well as structure.
Optionally, you can provide a type for the expected value via a generic. This is particuarly useful for ensuring expected objects have the right structure.
Used to test that a function throws when it is called.
If you want to test that a specific error is thrown inside a function.
Used to test that a function throws a error matching the most recent snapshot when it is called. Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
Used to test that a function throws a error matching the most recent snapshot when it is called.
Ensures the last call to a mock function was provided specific args.
Optionally, you can provide a type for the expected arguments via a generic. Note that the type must be either an array or a tuple.