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 particularly useful for ensuring expected objects have the right structure.
Optional
expected: EEnsure 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 particularly useful for ensuring expected objects have the right structure.
Optional
expected: EChecks 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 particularly useful for ensuring expected objects have the right structure.
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 particularly 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 uses ===
, a strict equality check.
It can also check whether a string is a substring of another string.
Optionally, you can provide a type for the expected value via a generic. This is particularly 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 particularly 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 particularly useful for ensuring expected objects have the right structure.
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 particularly useful for ensuring expected objects have the right structure.
Optional
expected: EUse 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 particularly useful for ensuring expected objects have the right structure.
Optional
expected: EUse 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.
Optional
value: EUse 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 particularly useful for ensuring expected objects have the right structure.
Optional
expected: EThis 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.
Optional
snapshot: stringThis 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.
Optional
snapshot: stringUsed 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.
Optional
snapshotName: stringThis ensures that a value matches the most recent snapshot. Check out the Snapshot Testing guide for more information.
Optional
snapshotName: stringEnsure 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 particularly useful for ensuring expected objects have the right structure.
Optional
value: EUse 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 particularly useful for ensuring expected objects have the right structure.
Used to test that a function throws when it is called.
Optional
error: string | RegExp | Constructable | ErrorIf you want to test that a specific error is thrown inside a function.
Optional
error: string | RegExp | Constructable | ErrorUsed 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.
Optional
snapshot: string
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.