toHaveProperties
Asserts that the value is an object that includes the same properties with the same values (strict equals) as the specified object.
toHaveProperties(object: any): void
Notes
- This method only checks for properties that strictly equal the specified property values. To check for nested properties, use a separate call for the properties of each object value.
Example
let obj = {
foo: "foo",
bar: 123,
baz: { x: 1, y: 2 }
};
// assert foo and bar property values
expect(obj).toHaveProperties({ foo: "foo", bar: 123 });
// assert baz property with x and y property values
expect(obj)
.toHaveProperty("baz")
.toHaveProperties({ x: 1, y: 2 })
Related
- class AssertionRepresents a value ready to be asserted.
- toHaveProperty(propertyName)Asserts that the value is an object that includes a property with given name (using the
in
operator).