Sometimes, we want to check multiple arguments on multiple calls for Jest spies with JavaScript.
In this article, we’ll look at how to check multiple arguments on multiple calls for Jest spies with JavaScript.
How to check multiple arguments on multiple calls for Jest spies with JavaScript?
To check multiple arguments on multiple calls for Jest spies with JavaScript, we can use the mockFn.mock.calls
property.
For instance, we write
expect(mockFn.mock.calls).toEqual([
[arg1, arg2],
[arg1, arg2],
]);
to call expect
with mockFn.mock.calls
to get the arguments that mockFn
is called with.
Then we call toEqual
with a nested array that has the array of arguments for each call of mockFn
to check if they match what we expect.
Conclusion
To check multiple arguments on multiple calls for Jest spies with JavaScript, we can use the mockFn.mock.calls
property.