0

I found that this still not mocking my function, when I console.log the module, it is still using real implementation.

jest.mock('./myFile', () => {
    const actual = jest.requireActual('./myFile');

    return {
        ...actual,
        firstAsyncFunction: jest.fn(),
        secondAsyncFunction: jest.fn(),
    };
});

it('outputs correctly', async () => {
    (firstAsyncFunction as jest.Mock).mockResolvedValue('value1');
    (secondAsyncFunction as jest.Mock).mockResolvedValue('value2');

    await act();

    expect(firstAsyncFunction as jest.Mock).toBeCalled();
    expect(secondAsyncFunction as jest.Mock).toBeCalled();
});
  • Does this answer your question? [How to mock functions in the same module using Jest?](https://stackoverflow.com/questions/45111198/how-to-mock-functions-in-the-same-module-using-jest) – jonrsharpe Jul 31 '23 at 18:59

0 Answers0