.toHaveBeenLastCalledWith(arg1, arg2, …)

Also under the alias: .lastCalledWith(arg1, arg2, …)

If you have a mock function, you can use .toHaveBeenLastCalledWith to test what arguments it was last called with. For example, let's say you have a applyToAllFlavors(f) function that applies f to a bunch of flavors, and you want to ensure that when you call it, the last flavor it operates on is 'mango'. You can write:

  1. test('applying to all flavors does mango last', () => {
  2. const drink = jest.fn();
  3. applyToAllFlavors(drink);
  4. expect(drink).toHaveBeenLastCalledWith('mango');
  5. });