scott.mebberson.codes

Jest

Jest

const mockFn = jest.fn()

Create a mock function.

expect(mockFn.mock.calls.length).toBe(2);

Assert the number of times the mock function has been called.

expect(mockFn.mock.calls[0][1]).toBe(action);

Assert the value of the first argument the first time the mock function was called.

expect(mockFn.mockReturnValueOnce(false).mockReturnValue(true));

Set the return value of the mock function.