Sometimes, we want to get the arguments called in a Jest mock function with JavaScript.
In this article, we’ll look at how to get the arguments called in a Jest mock function with JavaScript.
How to get the arguments called in a Jest mock function with JavaScript?
To get the arguments called in a Jest mock function with JavaScript, we call toHaveBeenCalledWith
.
For instance, we write
expect(mockedFunction).toHaveBeenCalledWith("param1", "param2");
to call expect
with the function we mocked.
And then we call toHaveBeenCalledwith
with the arguments that we want to check the mockedFunction
is called with.
This is done in our test callback.
Conclusion
To get the arguments called in a Jest mock function with JavaScript, we call toHaveBeenCalledWith
.