expect.objectContaining() matches an object that contains and matches all of the properties in the expected
object. Note that received object may be a superset of the expected object and contain some extra properties.
Use this method inside
expect(value).toEqual(expected)
to perform pattern matching. Object properties can be matchers to further relax the expectation. See examples.
Usage
// Assert some of the properties. expect({ foo:1, bar:2 }).toEqual(expect.objectContaining({ foo:1 }));
// Matchers can be used on the properties as well. expect({ foo:1, bar:2 }).toEqual(expect.objectContaining({ bar:expect.any(Number) }));
expect.objectContaining()matches an object that contains and matches all of the properties in the expected object. Note that received object may be a superset of the expected object and contain some extra properties.Use this method inside expect(value).toEqual(expected) to perform pattern matching. Object properties can be matchers to further relax the expectation. See examples.
Usage