Skip to content
Advertisement

How to check multiple arguments on multiple calls for jest spies?

I have the following function in a React component:

JavaScript

This is my test that at least gets the spy to be called:

JavaScript

However, the assertion is not working:

JavaScript

What is the right way to use toHaveBeenCalledWith?

Advertisement

Answer

I was able mock multiple calls and check the arguments this way:

JavaScript

where mockFn is your mocked function name.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement