stubbing a function using jest
With jest you should use jest.spyOn: jest .spyOn(jQuery, “ajax”) .mockImplementation(({ success }) => success([ 1, 2, 3 ])); Full example: const spy = jest.fn(); const payload = [1, 2, 3]; jest .spyOn(jQuery, “ajax”) .mockImplementation(({ success }) => success(payload)); jQuery.ajax({ url: “https://example.api”, success: data => spy(data) }); expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledWith(payload); You can try live example on codesandbox: … Read more