expect.not.objectContaining(object)

expect.not.objectContaining(object) matches any received object that does not recursively match the expected properties. That is, the expected object is not a subset of the received object. Therefore, it matches a received object which contains properties that are not in the expected object.

It is the inverse of expect.objectContaining.

  1. describe('not.objectContaining', () => {
  2. const expected = {foo: 'bar'};
  3. it('matches if the actual object does not contain expected key: value pairs', () => {
  4. expect({bar: 'baz'}).toEqual(expect.not.objectContaining(expected));
  5. });
  6. });