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

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

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 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