Reputation: 41
before(function (done) {
mongoose.connection.close();
done();
});
I'm doing tests using mocha testing framework after the test finishes my terminal is still running, and I found that method in the documentation but I'm getting an error says
Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called;
if returning a Promise, ensure it resolves. (C:\test\demo_test.js)
Upvotes: 1
Views: 167
Reputation: 8773
It returns the promises so you need to listen to it. You can use async/await or then/catch:
before(async function (done) {
await mongoose.connection.close();
done();
});
Also, you should close the connection in after instead of before. Check this for refactoring your test code.
Upvotes: 1