I\'m trying to mock axios.create() because I\'m using its instance across the app and obviously need all of its implementation which is destroyed by the mock, thus
You can use jest's genMockFromModule. It will generate jest.fn()
for each of the modules's methods and you'll be able to use .mockReturnThis()
on create
to return the same instance.
./src/__mocks__/axios.js
const axios = jest.genMockFromModule('axios');
axios.create.mockReturnThis();
export default axios;
working example