我有一个没有 async/await 语法的 chai 测试,但它会崩溃。如何解决?
错误是:
error 错误 [ERR_SERVER_ALREADY_LISTEN]:Listen 方法已被多次调用而没有关闭。代码:'ERR_SERVER_ALREADY_LISTEN'
这是使用经典语法和非工作 async/await 语法的相同测试:
chai.use(chaiHttp);
const api = chai.request(server).keepOpen();
// async/await => doesn't work
describe("GET /user/:id", () => {
it("return user information", async (done) => {
const res = await api
.get("/user/123")
.set("Cookie", "_id=567;locale=en");
chai.expect(res.status).to.equal(200);
done();
});
});
// classic syntax => works
describe("GET /user/:id", () => {
it("return user information", () => {
api
.get("/user/123")
.set("Cookie", "_id=567;locale=en")
.end(function (err, res) {
chai.expect(res).to.have.status(200);
});
});
});