Categories
JavaScript Answers

How to get the arguments called in a Jest mock function?

Spread the love

Sometimes, we want to get the arguments called in a Jest mock function.

In this article, we’ll look at how to get the arguments called in a Jest mock function.

How to get the arguments called in a Jest mock function?

To get the arguments called in a Jest mock function, we can use the toHaveBeenCalledWith method to check what a mocked function is called with.

For instance, we write

expect(mockedFunction).toHaveBeenCalledWith("foo", "bar");

to check the mockedFunction is called with 'foo' and 'bar' with toHaveBeenCalledWith.

Conclusion

To get the arguments called in a Jest mock function, we can use the toHaveBeenCalledWith method to check what a mocked function is called with.

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 *