Sometimes, we want to check that an argument to a mocked function is a function with Jest.
In this article, we’ll look at how to check that an argument to a mocked function is a function with Jest.
How to check that an argument to a mocked function is a function with Jest?
To check that an argument to a mocked function is a function with Jest, we can use the toBeCalledWith
method.
For instance, we write
expect(AP.require).toBeCalledWith('messages', expect.any(Function))
to check that AP.require
is called with 'messages'
and a function respectively.
expect.any(Function)
checks that the argument of AP.require
is a function.
Conclusion
To check that an argument to a mocked function is a function with Jest, we can use the toBeCalledWith
method.