1 year ago

#382193

test-img

Kgn-web

Jest has detected the following 1 open handle potentially keeping Jest from exiting: ā— TCPSERVERWRAP

I'm setting unit test for my nodejs app. To test the setup I have a very simple express route which looks as below

todo.ts

import { Router } from "express";
const router = Router();

router.get("/todo", async (req, res) => {
 return res.status(200); 
});

export default router;

Then I have created a folder _tests with a subfolder unit

todo.test.ts

/*
* @group unit
*/

import request, { SuperAgentTest } from "supertest";
import app from "../../../server";

let router: SuperAgentTest;

beforeAll(async () => {
 router = request.agent(app);
});

afterAll(async () => {
 await dbClose();
});

describe("ToDo API", () => {
 // Test Case -> 200
 it("Should return 200", async () => {
 const result = await router.get("/todo");
 expect(result.status).toEqual(200);
 });
});

I have the script in my package.json to run the unit tests is

"test:unit": "jest --verbose --detectOpenHandles --group=unit",

Now when I'm running the test from cmd/bash npm run test:unit I keep getting the below error

Jest has detected the following 1 open handle potentially keeping Jest from exiting:
ā— TCPSERVERWRAP

What's is causing this & how to get rid of it?

Thanks!

node.js

express

unit-testing

jestjs

ts-jest

0 Answers

Your Answer

Accepted video resources