How to check multiple arguments on multiple calls for jest spies?
I was able mock multiple calls and check the arguments this way:
expect(mockFn.mock.calls).toEqual([ [arg1, arg2, ...], // First call [arg1, arg2, ...] // Second call]);
where mockFn
is your mocked function name.
Since jest 23.0 there is .toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....)
https://facebook.github.io/jest/docs/en/expect.html#tohavebeennthcalledwithnthcall-arg1-arg2-
The signature is .toHaveBeenCalledWith(arg1, arg2, ...)
, where arg1, arg2, ...
means in a single call (see).
If you want to test multiple calls, just expect
it multiple times.
Unfortunately, I have not yet found a method to test the order of multiple calls.