Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda