Jest how to assert that function is not called

Sachin picture Sachin · Dec 8, 2017 · Viewed 36.2k times · Source

In Jest there are functions like toeCalled or toBeCalledWith to check if a particular function is called. Is there any way to check that a function is not called?

Answer

zer0chain picture zer0chain · Dec 8, 2017

Just use not.

expect(mockFn).not.toHaveBeenCalled()