Compares contents of the value with contents of
expected,
performing "deep equality" check.
For objects, this method recursively checks equality of all fields, rather than comparing objects by reference as
performed by
expect(value).toBe(expected).
expect(value).toEqual(expected)
can be also used to perform pattern matching on objects, arrays and primitive types, with the help of the following
matchers:
Compares contents of the value with contents of
expected, performing "deep equality" check.For objects, this method recursively checks equality of all fields, rather than comparing objects by reference as performed by expect(value).toBe(expected).
For primitive values, this method is equivalent to expect(value).toBe(expected).
Usage
Non-strict equality
expect(value).toEqual(expected) performs deep equality check that compares contents of the received and expected values. To ensure two objects reference the same instance, use expect(value).toBe(expected) instead.
expect(value).toEqual(expected) ignores
undefinedproperties and array items, and does not insist on object types being equal. For stricter matching, use expect(value).toStrictEqual(expected).Pattern matching
expect(value).toEqual(expected) can be also used to perform pattern matching on objects, arrays and primitive types, with the help of the following matchers:
Here is an example that asserts some of the values inside a complex object: