Closed DatVuGcc closed 5 years ago
I used this in my __mocks__/axios.js
file:
import mockAxios from 'jest-mock-axios';
export default {
...mockAxios,
create: jest.fn(() => ({
...mockAxios,
defaults: {
headers: {
common: {}
}
},
interceptors: {
request: {
use: jest.fn()
},
response: {
use: jest.fn()
}
}
}))
};```
@marvinkome works smooth! Thanks.
import mockAxios from 'jest-mock-axios'; export default { ...mockAxios, create: jest.fn(() => ({ ...mockAxios, defaults: { headers: { common: {} } }, interceptors: { request: { use: jest.fn() }, response: { use: jest.fn() } } })) };
Didn't help. Still have the same issue.
That's a duplicate of #5.
I'm trying to use mockAxios for testing with axios interceptors.
When I created mockAxios: export default { get: jest.fn(() => Promise.resolve(data: {})) } All of my tests failed with the follow message: cannot read property response of undefined inside of axios interceptors. It happens because mock axios doesn't return response. It could just return a plain object. So how can I use axios interceptors with mockAxios for testing?