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.