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

205
Visualizações
Timeout and beforeEach error when testing postgres database using Mocha

I am trying to test whether my test database is returning the correct data, but I keep getting the same error no matter what I do. I am still very much a beginner with testing, especially using Mocha, so any help is much appreciated.

I tried setting the Mocha timeout to 20 seconds, but it still doesn't pass. This is the error that I am getting:

1) Database Tests
    loadDataTest
        "before each" hook for "load_DataIsLoadedFromDatabase_IsTrue":
    Error: Timeout of 20000ms exceeded. For async tests and hooks, ensure "done()" is called; if
    returning a Promise, ensure it resolves. (/home/pi/Desktop/AQM/AQMBase/test/Databasetests.js)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) 

This is what my test looks like:

describe("loadDataTest", function() {
    beforeEach(async function(done) {
        let client = base.database.CreateClient();
        await client.query("TRUNCATE TABLE measurements;");

        let data1 = {
            "Sensor": "TestSensor",
            "Time": "2022-01-01 10:00",
            "Air_Quality": 1000,
            "Humidity": 50,
            "Temperature": 20
        }
        let data2 = {
            "Sensor": "TestSensor",
            "Time": "2022-01-01 11:00",
            "Air_Quality": 1100,
            "Humidity": 51,
            "Temperature": 21
        }
        let data3 = {
            "Sensor": "TestSensor",
            "Time": "2022-01-01 12:00",
            "Air_Quality": 1200,
            "Humidity": 52,
            "Temperature": 22
        }

        await base.database.add(data1);
        await base.database.add(data2);
        await base.database.add(data3);
        done();
    });

    it.only("load_DataIsLoadedFromDatabase_IsTrue", async function() {
        //Arrange
            

        //Act
        let result = await base.database.load();
        console.log(result);

        //Assert
        //assert.equal(result, );
    });
});

I am aware that I still need to write some actual code for testing, but it seems that the error is formed in the beforeEach section, since if I comment it out, the test passes. I have been looking all over the internet for a solution to this, and I just can't seem to figure it out.

about 4 years ago · Juan Pablo Isaza
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