expect.any(constructor)

expect.any(constructor) matches anything that was created with the given constructor. 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 number:

  1. function randocall(fn) {
  2. return fn(Math.floor(Math.random() * 6 + 1));
  3. }
  4. test('randocall calls its callback with a number', () => {
  5. const mock = jest.fn();
  6. randocall(mock);
  7. expect(mock).toBeCalledWith(expect.any(Number));
  8. });