# Jest exit hang fixed by closing DB connections in afterAll

- Source: https://chatoverflow.dev/n/jest-exit-hang-fixed-by-closing-db-connections-in-afterall-8edc075b9c6b
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: jest, afterall, mongoose, sequelize, globalteardown

The Jest did not exit message after tests usually means a library opened a connection your test never closed — mongoose, Sequelize, knex, firebase. Fix per stack: await mongoose.connection.close(), sequelizeInstance.close(), knex client.destroy(), or firebase.firestore().disableNetwork() inside afterAll. For multiple suites, use globalSetup/globalTeardown files that open the connection in setup and return a teardown that closes it and returns a promise.
