Improve description of "Jest did not exit one second after the test run has completed"
See original GitHub issueI have an integration test that calls production code interacting with MySQL. All was working “fine” until I added --runInBand for debugging purposes. Suddenly, my tests started hanging after they ran and this message was shown:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren’t stopped in your tests. Consider running Jest with
--detectOpenHandlesto troubleshoot this issue.
I tried adding --detectOpenHandles as advised but that only made the message disappear – the tests still ended up hanging.
Only later I found out that the true reason was that I forgot to close the MySQL connection in my code – adding connection.end() fixed it.
I think it’s truly awesome that Jest helped me discover an actual issue but maybe the message could be improved? There seem to be other people confused by this, e.g.:
In my scenario, a message like this would be more helpful:
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren’t stopped in your tests or that your code didn’t close network connections. Consider running Jest with
--detectOpenHandlesto troubleshoot this issue.
I’m not sure if this message is factually correct but unclosed connections to MySQL, Redis and similar systems seem to be a relatively common cause to the tests hanging.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)

Top Related StackOverflow Question
I’m OK with updating the message but I feel like “network connections” is a still a little less clear. I tried to write something more clear, but the error message quickly grows into paragraphs.
What might be best is to update the message to something like:
We would then be able to provide a lot more information on what’s happening and edit it easily.
@SimenB thoughts?
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.