I\'m new to JEST and I\'m currently testing a Javascript component that makes an API call in its onComponentDidMount. Depending on the return data of the ajax call (api call
If you want the mock to return different results on each call:
Use mockReturnValueOnce
myMock
.mockReturnValueOnce(10)
.mockReturnValueOnce('x')
.mockReturnValue(true);
will return 10
on the first call, 'x'
on the second call and true
anytime after that.
If you want to check the arguments that the mock has been called with:
Use toHaveBeenNthCalledWith
expect(mock).toHaveBeenNthCalledWith(1, 'first call args');
expect(mock).toHaveBeenNthCalledWith(2, 'second call args');