Currently, I am conducting a basic end-to-end testing procedure which seems to be failing at the moment. The primary issue I am facing is being unable to resolve an open handle.
A result of running all test suites reveals that Jest has identified one open handle that may prevent Jest from exiting:
● TCPSERVERWRAP
40 | }
41 | return request(app.getHttpServer())
> 42 | .post('/graphql')
| ^
43 | .send(mutation)
44 | .expect(HttpStatus.OK)
45 | .expect((response) => {
at Test.Object.<anonymous>.Test.serverAddress (../node_modules/supertest/lib/test.js:61:33)
at new Test (../node_modules/supertest/lib/test.js:38:12)
at Object.obj.<computed> [as post] (../node_modules/supertest/index.js:27:14)
at Object.<anonymous> (app.e2e-spec.ts:42:8)
import { Test, TestingModule } from '@nestjs/testing'
import { HttpStatus, INestApplication } from "@nestjs/common";
import * as request from 'supertest'
import { AppModule } from '../src/app.module'
describe('AppController (e2e)', () => {
let app: INestApplication
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile()
app = moduleFixture.createNestApplication()
await app.init()
})
afterAll(async () => {
await app.close()
})
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(HttpStatus.OK)
.expect('Hello World!')
})
it('mutation', async () => {
const mutation = {
query: `mutation Create($title: String!) {
create(title: $title) {
id,
title
}
}`,
variables: {
title: 'Mon programme',
},
}
return request(app.getHttpServer())
.post('/graphql')
.send(mutation)
.expect(HttpStatus.OK)
.expect( (response) => {
expect(response.body).toBe({
id: expect.any(String),
title: 'Mon programme',
})
})
})
})
Can anyone help identify what might be causing the obstruction in the test runner?
It is worth noting that I am utilizing NestJs and therefore should not require the use of the .end(done)
method at the conclusion of the test.
P.S.: It appears there is an excess of code provided in this question, but I am unsure what additional details could be included.