Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
closing connection in mongoos.js after test finishes with mocha.js
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)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!