DEV Community

Discussion on: Unit testing NestJS with mongo in memory...

deejoe79 profile image

Thank you for the article, this was very helpful. I also got the "Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with --detectOpenHandles to troubleshoot this issue."

The advice was not practical for me because in VSCode I often run 1-2 tests only (using the extension: Jest Runner).

I share what worked for me. Go to the MongooseTestModule.ts (typescript please :)

import mongoose from 'mongoose';
Enter fullscreen mode Exit fullscreen mode
export const closeInMongodConnection = async () => {
    await mongoose.disconnect();
    if (mongod) await mongod.stop();
Enter fullscreen mode Exit fullscreen mode
bassochette profile image
Julien Prugne Author

Thanks for you help ❤
I'll try to update the post and the sample code repo on github.