• Jobs
  • About Us
  • Jobs
    • Home
    • Jobs
    • Courses and challenges
  • Businesses
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Hire tech talent
    • Blog
    • Sales
    • Salary Calculator

0

182
Views
Supertest se agota en la solicitud posterior

Estoy tratando de usar supertest para probar algunas rutas rápidas, sin embargo, la prueba arroja un error de tiempo de espera cuando intento enviar solicitudes de publicación a pesar de que las solicitudes de obtención realmente funcionan.

esta es la ruta que estoy probando

 router.post('/', async (req, res) => { try { const { command, text } = req.body; switch (command) { case 'abc': return; default: console.log('123'); } } catch (error) { console.error(error); } });

esta es la prueba

 describe('test', () => { const app: express.Express = express(); app.use('/', route); app.use(express.urlencoded({ extended: true })); it('test', async () => { await request(app) .post('/') .send('command=john') expect(handleSurveyListCommand).not.toHaveBeenCalled(); expect(handleSurveyRespondCommand).not.toHaveBeenCalled(); expect(consoleErrorSpy).toHaveBeenCalledTimes(1); expect(consoleErrorSpy).toHaveBeenCalledWith(new Error('Command not found')); }); });

y este es el error que arroja

 Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error:

esta prueba falla incluso si lo único que hago dentro de la ruta es registrar algo.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto se debe a que no está respondiendo con la respuesta mientras la solicitud en el caso de prueba está esperando alguna respuesta, en lugar de eso, intente enviar la respuesta.

 router.post('/', async (req, res) => { try { const { command, text } = req.body; switch (command) { case 'abc': res.status(200).send("abc"); default: res.status(200).send("123"); } } catch (error) { res.status(500).send("unknown error"); } });

Con respecto a req.body indefinido -> usar cuerpo analizado en la aplicación

 app.use(express.bodyParser());
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!