Skip to content

MSW does not intercept Api requests #1605

Answered by wiskani
wiskani asked this question in Q&A
Discussion options

You must be logged in to vote

I resolved the issue by including the "fetch" function in my test environment using the "whatwg-fetch" library:

import 'whatwg-fetch';
import '@testing-library/jest-dom';
import { server } from './src/mocks/server';

beforeAll(() => {
  server.listen();
  console.log('Server is listening...');
});

afterEach(() => {
  server.resetHandlers();
});

afterAll(() => {
  server.close();
});

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@wiskani
Comment options

@kettanaito
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@kettanaito
Comment options

Answer selected by wiskani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants