从0.35.0开始我就一直在使用垃圾。最近,我将其更新为v0.40.1,现在看来MSW没有拦截对服务器的请求,我收到了以下错误。
这是我的测试代码。
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);
});
});这就是我所犯的错误。
错误:请求失败,状态代码400在createError () at IncomingMessage.handleStreamEnd () at IncomingMessage.emit (节点:events:402:35)的endReadableNT (节点: failed /streams/可读:1343:12)在processTicksAndRejections (节点:内部/进程/任务队列:83:21)
以下是我使用的其他软件包的版本。
我读过MSW的示例,我不认为我的实现有任何问题。
发布于 2022-06-14 03:23:36
也许这个问题是相关的。https://github.com/mswjs/msw/issues/1125
这个问题已经解决了5天前,所以我相信一个修正版本将在不久的将来发布。
顺便说一下,降级到0.36.8是暂时的解决办法。
https://stackoverflow.com/questions/72446299
复制相似问题