Is it possible to test the response from NodeJs using Mocha?
A GET request is made using $http from AngularJs to NodeJs. On success of the request this function is called:
var successCallback = function (data) {
var SUCCESS_STATUS_CODE = 200;
response.set('Content-Type', 'application/json');
response.send({
statusCode: SUCCESS_STATUS_CODE,
data: data
});
};
I have tried to use Sinon to spy on the function and also Mocha to check the request but I cannot get them to work. What is the best way to write a test to check that the output from "response.send"?
To test a response of a HTTP call from Node.JS, you could use superagent
Create a folder and install inside mocha and superagent:
Then create a file called something like test.js with this code:
then you can run it with mocha