I am trying to build a test using Jest and Supertest for my loopback 3 rest API server. The test is running, but Jest did not exit gracefully.
This is my test script branch.test.js:
const app = require('../server/server');
const request = require('supertest');
describe('Test the root path', () => {
afterAll(done => {
app.close(done);
});
test('It should response the GET method', async () => {
const response = await request(app).get('/api/branches');
expect(response.statusCode).toBe(200);
});
})
And package.json for test setting
{
"scripts": {
"lint": "eslint .",
"start": "node .",
"posttest": "npm run lint",
"test": "jest --detectOpenHandles"
},
"jest": {
"testEnvironment": "node"
}
}
Every time I run npm run test, the log always return:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● TCPWRAP
11 |
12 | test('It should response the GET method', async () => {
13 | const response = await request(app).get('/api/branches');
14 | expect(response.statusCode).toBe(200);
15 | });
16 | })
at Test.Object..Test.serverAddress (node_modules/supertest/lib/test.js:59:33)
at new Test (node_modules/supertest/lib/test.js:36:12)
at Object.obj.(anonymous function) [as get] (node_modules/supertest/index.js:25:14)
at Object.get (test/unit/branch.test.js:13:45)
the log is pointing at get function. People in forum use jest --forceExit, but it is not the way I want. Are there any solutions for this problem? Thanks for the response
Aucun commentaire:
Enregistrer un commentaire