Web*_*per 5 apollo jestjs graphql apollo-server
我将测试使用 Jest 运行的后端服务器。有时会成功,但有时会显示这样的错误。

因此,如果我按照建议使用 --detectOpenHandles 标志,它总是成功而不显示任何错误。这是测试代码。
it("should be able to initialize a server (development)",async (done) => {
// Before main() is called there is no active connection:
expect(connection.readyState).toBe(0);
return main({
env: "dev",
port: PORT,
})
.then(async (server: ApolloServer) => {
// After main() got called, there is an active connection:
expect(connection.readyState).toBe(1);
await server.stop();
done();
})
});
afterAll(async () => {
await connection.close(); //connection is mongoose.connection
});
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它在标记时失败。奇怪的是,有时成功,有时失败。
谢谢
我遇到了类似的问题,并通过在传递给 的函数中返回一个承诺来解决它afterAll。例如:
afterAll(() => {
return connection.close(); // connection.close() returns a promise
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1051 次 |
| 最近记录: |