Reputation: 9242
While running end-to-end tests of NestJS+Fastify application I noticed the following warnings:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with
--detectOpenHandles
to troubleshoot this issue.
When adding the --detectOpenHandles
option I saw the following:
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
So what's the problem?
Upvotes: 0
Views: 1085
Reputation: 9242
The pasted example is incomplete, application has to be closed manually just like in the Express example:
afterAll(async () => {
await app.close();
});
And the warning is gone. Also created a PR to improve NestJS' docs.
Upvotes: 0