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

278
Vistas
How to test req.query using supertest node.js?

I have this code on supertest framework for tests:

it('GET normal pending transfer with receiverId', (done) => {
      supertest(app)
        .get('/transfers/pending')
        .set('Accept', 'application/json')
        .expect(200)
        .query({
          senderId: clientSenderId,
        })
        .expect('Content-Type', 'application/json; charset=utf-8')
        .then((res) => {
          console.log('res.body', res.body);
          done();
        })
        .catch(done);
    });

This endpoint - /transfers/pending takes query this way:

const { receiverId, senderId } = req.query;

As you can see, this is req.query and I want to send this query in my test's code.

I was trying to use this:

.get('/transfers/pending?senderId=${clientSenderId}')

And this:

.query({
  senderId: clientSenderId,
})

And nothing of this isn't working. I mean, I got 500 and, the most important, I get an error in message, that belongs to other endpoint. It looks like my code triggers other endpoint, not that /transfers/pending.

My question is, how can I send queries in tests. With params and bodies everything works just fine, but not with queries.

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