In Jest there are functions like tobeCalled
or toBeCalledWith
to check if a particular function is called. Is there any way to check that a function is not called?
Just use not
.
expect(mockFn).not.toHaveBeenCalled()
See the jest documentation
not
did not work for me, throwing a Invalid Chai property: toHaveBeenCalled
But using toHaveBeenCalledTimes
with zero does the trick:
expect(mock).toHaveBeenCalledTimes(0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With