.toHaveBeenCalledWith(arg1, arg2, …)

Also under the alias: .toBeCalledWith()

Use .toHaveBeenCalledWith to ensure that a mock function was called with specific arguments.

For example, let's say that you can register a beverage with a register function, and applyToAll(f) should apply the function f to all registered beverages. To make sure this works, you could write:

  1. test('registration applies correctly to orange La Croix', () => {
  2. const beverage = new LaCroix('orange');
  3. register(beverage);
  4. const f = jest.fn();
  5. applyToAll(f);
  6. expect(f).toHaveBeenCalledWith(beverage);
  7. });