TL; DR; Jest did not exit one second after the test run? Nothing seems to work and you are not sure what process is still running? Use globalTeardown in combination with process.exit(0).
The Problem
Recently a colleague of mine had this problem when his jest tests were running but at the end this message was showing up.
Jest did not exit one second after the test run has completed. There is a tip for running the command with “--detectOpenHandles”
to troubleshoot this issue.
The problem is that some asynchronous operations weren’t stopped before the tests finished. It could be that you are testing something that is starting some services in the background that needs to be killed at the end."
When you know what is running in the background, it’s good; you have a chance, but what should you do when you don’t know how to stop the services?
Solution
Step 1
Step 2
Step 3
Rerun the test.
Have a great day!
Note: The gifs are from giphy.com