-
-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error interceptor breaks on tests using some mock library #4518
Comments
maybe is an error on axios-mock-adapter or in msw, but I already fixed by using // my-api.ts
export const MyApi = (baseURL?: string) => {
const api = axios.create({ baseURL });
api.interceptors.response.use(
(data)=> data,
(error)=> {
// Now it enters here
return Promise.reject({
...error,
customError: error.message,
});
},
);
return api;
}; // my-api.spec.ts
import MockAdapter from 'axios-mock-adapter';
import { MyApi } from './my-api';
describe('my-api', () => {
// NOTE: simulate an instance of the api
const api = MyApi('http://localhost');
const apiMock = new MockAdapter(api);
it('should handler request error interceptor', async () => {
try {
apiMock.onGet('/fake_data').reply(404);
await api.request({ method: 'get', url: '/fake_data' });
} catch (error) {
const { customError } = error as { customError: string };
expect(customError).toBe('example error');
}
});
}); |
closing as i dont think this is relevant anymore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Error on reject interceptor on tests using axios-mock-adapter or msw.
Trying to have an Axios class with custom interceptors. but, when I try to test a mock and test the rejected interceptor, it never pass through the rejected response interceptor
It work's on the browser, and if I remove the mocking library (for example:
axios-mock-adapter
) it works. but without mocking the expecting data.To Reproduce
Expected behavior
it should enter into the error interceptor
Environment
The text was updated successfully, but these errors were encountered: