I'm testing a UDP server, and to do that, I created a UDP client within the test. However, despite the test passing, Jest exits with the following message:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
It points to the line where I declared the UDP socket.
I tryed the following code:
const dgram = require('node:dgram');
describe("udp client", () => {
let testClient = dgram.createSocket('udp6');
test('test', ()=>{
let popo = false
expect(popo).toEqual(false);
})
});
But sitll I am getting the same problem:
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● UDPWRAP
2 |
3 | describe("udp client", () => {
> 4 | let testClient = dgram.createSocket('udp6');
| ^
5 | test('test', ()=>{
6 | let popo = false
7 | expect(popo).toEqual(false);
at createSocket (test/test_udp.test.js:4:28)
at Object.describe (test/test_udp.test.js:3:1)
That is not a serious problem, but i like to know what is going on.
Jest is kept "alive" by an open socket, which you have to close explicitly by calling socket.close()
. A good place to do it is in afterEach()
or afterAll()
hook.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.