I've been using MSW since v0.35.0. Recently I updated it to v0.40.1 and now it seems like MSW is not intercepting the request to the servers and I'm getting the following error.
Here is my test code.
import axios from 'axios';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
const path = 'login/';
const accessToken = 'AccessTokenValue';
const correctCredential = { email: 'test@email.com', password: 'password' };
const server = setupServer(
rest.post(path, (req, res, ctx) => {
return res(ctx.status(200), ctx.json({ data: { access: accessToken } }));
}),
);
beforeAll(() => server.listen());
afterAll(() => server.close());
afterEach(() => server.resetHandlers());
describe('Login', () => {
test('Case: Success', async () => {
let token = '';
await axios
.post('https://test.com' + path, correctCredential)
.then((response) => (token = response.data.data.access));
expect(token).toBe(accessToken);
});
});
And this is the error I get.
Error: Request failed with status code 400
at createError (<my_local_path>) at settle (<my_local_path>) at IncomingMessage.handleStreamEnd (<my_local_path>) at IncomingMessage.emit (node:events:402:35) at endReadableNT (node:internal/streams/readable:1343:12) at processTicksAndRejections (node:internal/process/task_queues:83:21)
Here are the versions of the other packages I use.
- jest: 27.0.6
- axios: 0.25.0
I read Examples from MSW and I don't see any problem with my implementation.