samedi 17 mars 2018

How to add params with GET request using nock.js

I am trying to test if my API routes are working using nock.js to mock url requests.

'loadStudy' method in 'abc.js' is used to handle the below particular GET request.

var abc = require('G:\\project\\abc.js');
var nock = require('nock');

var api = nock("http://localhost:3002")
          .get("/api/test/load/1")
          .reply(200, abc.loadStudy);

request({ url : 'http://localhost:3002/api/study/load/1', method: 'GET', params: {id : 1}}, function(error, response, body) { console.log(body);} ); 

However, my method makes use of 'params' key that is sent with request which I'm not able to mock. Printing 'req' in the below code just gives '/api/test/load/1' . How can I add 'params' to the GET request?

loadStudy = function(req, res) {
    console.log(req);
    var id = req.params.id;
};

Aucun commentaire:

Enregistrer un commentaire