问题
I am trying to mock axios module inside my test file like this.
import axios from 'axios';
jest.mock('axios', () => ({
__esModule: true,
create: jest.fn(),
get: jest.fn(),
post: jest.fn(),
default:jest.fn()
}));
jest.mock("../../utils/api");
Here is mocked API in a folder __mocks__
//../../utils/api
const mockLogin = jest.fn((email, password) => {
return Promise.resolve({ email, password });
});
const errors = jest.fn((errors) =>{
return errors
});
module.exports =
{
...jest.requireActual("../../utils/api"),
__esModule: true,
mockLogin,
post: mockLogin,
catchErrors:errors
}
When I run my test I get the following error.
What is wrong with my code?
This is not duplicate, because the solution provided does not solve the problem whatsoever
来源:https://stackoverflow.com/questions/64961204/mocking-api-calls-with-jest