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

200
Vistas
How can I increase the test time out value in jest?

I want to verify a function that can get update after one minute, and I set some sleep in my code, but my default time out value is 15000 ms, my code has sleep 60000ms so it returns this error:

thrown: "Exceeded timeout of 15000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value,
    if this is a long-running test."

my code is here:

it('shows that timeline can get updated after one minute', async () => {
    await selectTimeForTimeLine.selectTime('Last 5 minutes');
    await page.waitForTimeout(3000);
    const defaultTime = await alarmTimeLine.xAxisValues();
    await page.evaluate(() => {
      return new Promise((resolve) => setTimeout(resolve, 60000));
    });
    const correntTime = await alarmTimeLine.xAxisValues();
    expect(defaultTime).not.toEqual(correntTime);
  });

Where should I put jest.setTimeOut()? I want to increase exceeded timeout value to 70000ms to make sure my code runs well.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

To set a timeout on a single test, pass a third option to it/test, for example:

 it('testing balabala', async () => {
   ...
 }, 70000);
about 4 years ago · Juan Pablo Isaza Denunciar

0

From the jest.setTimeout() docs:

Set the default timeout interval for tests and before/after hooks in milliseconds. This only affects the test file from which this function is called.

Ie jest.setTimeout() is handled on a file level. Their example doesn't make it clear, but you should have run jest.setTimeout() at the top of your test file:

const SECONDS = 1000;
jest.setTimeout(70 * SECONDS)

describe(`something`, () => {
  it('works', async () => {
    asset(true).isTruthy()
  });
})

Update: I've now sent a PR to the Jest team, which has been accepted, to clarify the docs. They now read:

To set timeout intervals on different tests in the same file, use the timeout option on each individual test.

about 4 years ago · Juan Pablo Isaza Denunciar

0

After upgrading to v28+, this jest.setTimeout() does not work for me anymore. I have to set the timeout explicitly in ./jest.config.js:

// jest.config.js
module.exports = {
    // ...
    testTimeout: 70000
}
about 4 years ago · Juan Pablo Isaza Denunciar
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