Skip to content

Commit ef40b5d

Browse files
committed
Close MongoDB connection in integration tests before stopping the container
1 parent ed5982d commit ef40b5d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

__tests__/db/mongodb-note-repository.integration.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {GenericContainer} from 'testcontainers';
22
import {MongoDbNoteRepository} from '../../src/db/mongodb-note-repository.js';
33
import {Note} from '../../src/models/note.js';
4+
import mongoose from 'mongoose';
45

56
describe('MongoDbNoteRepository Integration Tests', () => {
67
let container;
@@ -37,6 +38,10 @@ describe('MongoDbNoteRepository Integration Tests', () => {
3738
afterAll(async () => {
3839
console.log('Stopping MongoDB container...');
3940
if (container) {
41+
// Close the MongoDB connection first
42+
await mongoose.connection.close();
43+
console.log('MongoDB connection closed');
44+
4045
await container.stop();
4146
console.log('MongoDB container stopped');
4247
}

0 commit comments

Comments
 (0)