Categories
TypeScript Answers

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

Spread the love

Sometimes, we want to check multiple arguments on multiple calls for Jest spies.

In this article, we’ll look at how to check multiple arguments on multiple calls for Jest spies.

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

To check multiple arguments on multiple calls for Jest spies, we can use the toEqual method with an array.

For instance, we write

expect(mockFn.mock.calls).toEqual([
  [arg1, arg2],
  [arg1, arg2],
]);

to get all the calls of mockFn with mockFn.mock.calls.

And then we check the arguments of the calls by calling toEqual with an array of argument arrays to check the calls against the entries in the arrays.

Conclusion

To check multiple arguments on multiple calls for Jest spies, we can use the toEqual method with an array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *