How can i use node-mocks-http for testing async? for eg: I have this in my express router which can be reached through GET /category/list
var getData = function (req, res) {
Category.find({}, function (err, docs) {
if (!err) {
res.json(200, { categories: docs });
} else {
res.json(500, { message: err });
}
});
};
and in the test
var request = httpMocks.createRequest({
method: 'GET',
url: '/category/list',
body: {}
});
var response = httpMocks.createResponse();
getData(request, response);
console.log(response._getData());
test.done();
but the response does not contain the json (response comes back later after a few seconds). How can i test this? Any help is much appreciated.
Aucun commentaire:
Enregistrer un commentaire