expect.anything()

expect.anything() matches anything but null or undefined. You can use it inside toEqual or toBeCalledWith instead of a literal value. For example, if you want to check that a mock function is called with a non-null argument:

  1. test('map calls its argument with a non-null argument', () => {
  2. const mock = jest.fn();
  3. [1].map(x => mock(x));
  4. expect(mock).toBeCalledWith(expect.anything());
  5. });