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

281
Visualizações
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 à 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