【发布时间】:2019-02-05 19:41:30
【问题描述】:
我将测试运行 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
});
我不确定为什么它在标记时失败。 奇怪的是它有时成功,有时失败。
谢谢
【问题讨论】:
标签: graphql jestjs apollo apollo-server