closing open handles detected by jest

Viewed 2894

i am writting tests for a node application which uses bull to process background jobs.

the test seems to be passing and working as expected but i am seeing the following error message

Jest has detected the following 
8 open handles potentially keeping 
Jest from exiting:

the log points to specifically this line and other similar statements.

 const csvExportsQueue = ['test', 'development'].includes(process.env.NODE_ENV) ? new Queue('exports') : new Queue('csv exports', 'redis://redis:6379/13');

I tried to add the below statement to my test but it still gives the same error


afterAll(async () => {
  await new Promise(resolve => setTimeout(() => resolve(), 10000)); // avoid jest open handle error
});

any help on how to fix this will be great, thanks.

1 Answers
  1. add "jest --detectOpenHandles" to "test" in package.json to see the openhandles for Debugging

  2. check your db connection (most likely) and close it them with connection.end()

Related