I'd like to request that we either add toBeCalledOnce() or toBeCalled(x) where x represents the number of times the mock function was called.
There is a subtle but significant difference between these two assertions:
expect(foo).toBeCalled()
expect(foo.mock.calls.length).toBe(1)
The difference is that the second asserts that it was called only one time. No more, no less. The first only asserts that it was called, not that it was only called one time.
actually.. we already have expect(jest.fn()).toHaveBeenCalledTimes(x)
but unfortunately it's not documented :)
sorry.. we're still cleaning things up in our documentation
Most helpful comment
actually.. we already have
expect(jest.fn()).toHaveBeenCalledTimes(x)but unfortunately it's not documented :)
sorry.. we're still cleaning things up in our documentation