Jest not terminating after tests complete successfully
Figured out the issue was that I was not doing enough in the afterAll()
hook.
I made a small repo to reproduce the issue and troubleshoot it from there and this was what needed to be done so that jest
could exit on successful completion of the test suite:
afterAll(async () => {
try {
const { todos } = mongoose.connection.collections;
// Collection is being dropped.
await todos.drop()
// Connection to Mongo killed.
await mongoose.disconnect();
// Server connection closed.
await server.close();
} catch (error) {
console.log(`
You did something wrong dummy!
${error}
`);
throw error;
}