Using exact equality with floating point numbers is a bad idea. Rounding means that intuitive things fail. The default for numDigits is 2.
OptionalnumDigits: numberEnsure 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.
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.
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.
Ensures that a mock function is called.
Ensures that a mock function is called an exact number of times.
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.
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.
Optionalexpected: EUsed 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 particularly useful for ensuring expected objects have the right structure.
Optionalexpected: 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.
Optionalvalue: EUse 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.
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.
Optionalsnapshot: 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.
Optionalsnapshot: 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.
OptionalsnapshotName: stringThis ensures that a value matches the most recent snapshot. Check out the Snapshot Testing guide for more information.
OptionalsnapshotName: stringUsed to test that a function throws when it is called.
Optionalerror: 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.
Optionalsnapshot: stringUsed to test that a function throws a error matching the most recent snapshot when it is called.
OptionalsnapshotName: string
Checks that a value is what you expect. It uses
Object.isto check strict equality. Don't usetoBewith 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.