Docs (4.0.0)
class Assertion method

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