Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

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