![](/img/trans.png)
[英]Nest e2e test : Jest did not exit one second after the test run has completed
[英]NestJS + Fastify e2e testing: Jest did not exit one second after the test run has completed
在運行 NestJS+Fastify 應用程序的端到端測試時,我注意到以下警告:
測試運行完成后一秒鍾,Jest 沒有退出。
這通常意味着在您的測試中沒有停止異步操作。 考慮使用
--detectOpenHandles
運行 Jest 來解決此問題。
添加--detectOpenHandles
選項時,我看到以下內容:
FAIL test/app.e2e-spec.ts
AppController (e2e)
✕ /GET cats (975 ms)
● AppController (e2e) › /GET cats
expect(received).toEqual(expected) // deep equality
Expected: 200
Received: 404
23 | })
24 | .then((result) => {
> 25 | expect(result.statusCode).toEqual(200);
| ^
26 | expect(result.payload).toEqual('API is running.');
27 | });
28 | });
at app.e2e-spec.ts:25:35
所以有什么問題?
似乎基於 Fastify 的應用程序與基於 Express 的應用程序不同,它本身並不存在。 我已經添加:
afterEach(async () => {
await app.close();
});
警告消失了。 還創建了一個PR 來改進 NestJS 的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.