You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
// my-api.tsimportaxiosfrom'axios';exportclassMyApiextendsaxios.Axios{constructor(baseURL: string){super({
baseURL,});this.interceptors.response.use((data)=>data,(error)=>{// Never enters herereturnPromise.reject({
...error,customError: error.message,});},);}}
// my-api.spec.tsimporttype{AxiosInstance}from'axios';importMockAdapterfrom'axios-mock-adapter';import{MyApi}from'./my-api';describe('my-api',()=>{// NOTE: simulate an instance of the apiconstapi=newMyApi('http://localhost');constapiMock=newMockAdapter(apiasAxiosInstance);it('should handler request error interceptor',async()=>{try{apiMock.onGet('/fake_data').reply(404);awaitapi.request({method: 'get',url: '/fake_data'});// NOTE: this should never happen since endpoint fails and enters directly on catchexpect(1).toBe(2);}catch(error){const{ customError }=erroras{customError: string};expect(customError).toBe('example error');}});});
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: