Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda