0
我有一个简单的服务器,它接受POST
请求,并在请求主体超出允许的大小时发出413 Request entity too large
错误的响应。当我使用Jest测试它时,请求有时会返回正确的错误,但更多时候它会返回{ code: EPIPE, syscall: write }
错误。使用Jest测试POST请求时出现`EPIPE`错误
我测试了服务器使用cURL和节点JavaScript文件和服务器按预期工作,但Jest测试仍然给我那个错误。我也尝试了另一个请求库,他们给出了同样的错误。
beforeAll(() => {
server.listen(testingPort);
});
afterAll(() => {
server.close();
});
describe("POST request",() => {
test("should return error 413 in respense to exceeded file size", async() => {
const fileContent = new Array(1024 * 1024 + 10).join("*");
const fileName = "post-test-file.txt";
const urlObj = new URL(fileName, host);
try {
await axios.post(urlObj.href, fileContent);
} catch (e) {
console.log(e.code, e.errno, e.syscall); // EPIPE EPIPE write
// expect(e.response.status).toBe(413);
}
});
也许您对此有任何想法?