i have some API and if i test them with postman its working fine. but if i try to test that API with same data in mocha js, some API are working and some are giving me an error like "500 internal server error" and "400 bad request".
i am sure that i am passing same data, same request and same authorization details in both postman and in mocha test script.
i have tried this in mocha and i am passing same data in postman, than why mocha giving me and error like this. my all server and database are up and working fine.
it("Updating User details: ", function (done) {
server
.put(apiUrl + "/user")
.set({
"name": "Vinay Pandya",
"photo": "http://tamilcinema.com/wp-content/uploads/2015/05/madhavan.jpg",
"email": "[email protected]",
"gender": "M"
})
.set({"Authorization": token})
.expect(200)
.end(function (err, res) {
if (err)
throw err;
res.status.should.equal(200);
res.body.status.should.equal("success");
//console.info(JSON.stringify(res.body));
});
done();
});
i solved this issue. i was using SET() instead of SEND(). if i want to send data, than i should use SEND(). SET() is for setting header for api request.
it("Updating User details: ", function (done) {
this.timeout(300);
server
.put(apiUrl + "/user")
.send({
"name": "Vinay Pandya",
"photo": "http://tamilcinema.com/wp-content/uploads/2015/05/madhavan.jpg",
"email": "[email protected]",
"gender": "M"
})
.set({"Authorization": token})
.expect(200)
.end(function (err, res) {
if (err)
throw err;
res.status.should.equal(200);
res.body.status.should.equal("success");
//console.info(JSON.stringify(res.body));
done();
});
});