question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supertest converts number query params to string

See original GitHub issue

Hello, I’m having an issue with supertest when I send a number param by query. The server catches the params as string.

PD: I’ve got a transform in the DTO to convert any string value into a number.

this is my test

it('should retrieve all the template with the params the limit,page', async (done) => {
    // Arrange
    let params = {
      limit: 10,
      page: 1
    }

    // Act
    const response = await supertest(app.getHttpServer())
      .get("/email/get")
      .set('Content-Type', 'application/json;charset=utf-8')
      .set("Content-Lenght", '51')
      .set('Authorization', 'bearer ' + globalToken)
      .query({ limit: params.limit, page: params.page })
  });

Any help ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
AustinGilcommented, Jun 22, 2021

Jumping in here for another opinion, but I thought query params were always parsed as strings and it’s up to you to convert them in your route handlers.

0reactions
niftylettucecommented, Jan 17, 2022

Querystring is a string. Your server code should parse keys in the querystring that should be converted to numbers manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supertest converts number query params to string #622
Hello, I'm having an issue with supertest when I send a number param by query. The server catches the params as string.
Read more >
how to send number query params in supertest request
I'm trying to test an API endpoint and for that I'm using supertest request, the thing is that the endpint is geting the...
Read more >
supertest.Test.query JavaScript and Node.js code examples
Best JavaScript code snippets using supertest.Test.query(Showing top 15 results out of 315) · test/controllers/location/location. · test/controllers/message/ ...
Read more >
Developers - Supertest converts number query params to string -
Hello, I'm having an issue with supertest when I send a number param by query. The server catches the params as string. PD:...
Read more >
mocha/supertest/nodejs How To Access Request ...
The code below works except that there is a query parameter added. var supertest = require('supertest'); var request = supertest('localhost:3001 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found