How to send query string parameters using supertest?

I use supertest to send query string parameters, how can I do this?

I tried

var imsServer = supertest.agent("https://example.com"); imsServer.get("/") .send({ username: username, password: password, client_id: 'Test1', scope: 'openid,TestID', response_type: 'token', redirect_uri: 'https://example.com/test.jsp' }) .expect(200) .end(function (err, res) { // HTTP status should be 200 expect(res.status).to.be.equal(200); body = res.body; userId = body.userId; accessToken = body.access_token; done(); }); 

but did not send username , password , client_id as a query string to the endpoint. Is there a way to send query string parameters using supertest?

+8
supertest
source share
1 answer

Although supertest not well documented, you can look at tests/supertest.js .

There you have a test suite for query strings only.

Something like:

 request(app) .get('/') .query({ val: 'Test1' }) .expect(200, function(err, res) { res.text.should.be.equal('Test1'); done(); }); 

Thus:

 .query({ key1: value1, ... keyN: valueN }) 

must work.

+23
source share

All Articles