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

197
Vistas
Supertest + express setup cause timeout error

I have a simple setup on the server.test.js

import 'regenerator-runtime/runtime';

const request = require('supertest');
const express = require("express")
const app = express();

app.get('/user', function(req, res) {
  res.status(200).json({ name: 'john' });
});

describe('GET /user', function() {
  it('responds with json', async function(done) {
    const response = await request(app)
      .get('/user')
    expect(response.status).toBe(201)
  })
})

npx jest and receive thrown: "Exceeded timeout of 5000 ms for a test., increasing timeout doesn't help in jest.config.js to testTimeout: 20000, it waits for the 20s and also fails

Why express app start with superset? I used an example from the official README

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

0

Try to remove done from the test callback:

it('responds with json', async function() {
  const response = await request(app)
    .get('/user')
  expect(response.status).toBe(201)
})

Jest may be waiting for it to be called.

Generally it's recommended that you either use an async function or done. Jest normally warns if you mix them, not sure why it doesn't do so wit this setup.

Alternatively you can try to call done() at the end of the test.

You should expect for the test to fail because the status that gets posted is 200 and you are checking for 201.

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