Categories
TypeScript Answers

How to fix the ‘Jest did not exit one second after the test run has completed’ error with TypeScript?

Spread the love

Sometimes, we want to fix the ‘Jest did not exit one second after the test run has completed’ error with TypeScript.

In this article, we’ll look at how to fix the ‘Jest did not exit one second after the test run has completed’ error with TypeScript.

How to fix the ‘Jest did not exit one second after the test run has completed’ error with TypeScript?

To fix the ‘Jest did not exit one second after the test run has completed’ error with TypeScript, we should make sure we clean up when our test is done.

For instance, we write

beforeAll((done) => {
  done();
});

//...

afterAll((done) => {
  mongoose.connection.close();
  done();
});

to call done after calling mongoose.connection.close(); to close the MongoDB connection after our test is done.

Then Jest knows that the test is done and ends the test.

Conclusion

To fix the ‘Jest did not exit one second after the test run has completed’ error with TypeScript, we should make sure we clean up when our test is done.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.