I have the following error after running my tests with --detectOpenHandles parameter
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● PROMISE
18 |
19 | mongoose.Promise = global.Promise;
> 20 | mongoose.connect(config.database.link, config.database.options);
| ^
21 |
22 |
23 | app.use(cors());
But my test includes mongoose.disconnect()
afterAll(() => {
return new Promise(res => mongoose.disconnect(() => {
res();
}));
});
I tried to change the afterAll function to something like this:
afterAll(async () => {
await mongoose.disconnect();
await mongoose.connection.close();
});
Also I tried to call con.disconnect inside of afterAll()
app.con = mongoose.connect(config.database.link, config.database.options);
// inside of afterAll
app.con.disconnect()
But I am still getting the same error message as shown above