Skip to main content

expect.exactly(value)

An asymmetric matcher that checks if the received value is exactly equal to the expected value, using Object.is.

Useful for situations where deep equality would typically be used, but you want to ensure that the values are the same reference.

const ref = {}
const mock = jest.fn();
mock(ref);

it("is exactly equal", () => {
  expect(mock).toHaveBeenCalledWith(expect.exactly(ref));
  expect(mock).not.toHaveBeenCalledWith(expect.exactly({}));

  // this would normally pass
  expect(mock).toHaveBeenCalledWith({});
});

Open browser consoleTests