Reputation: 16805
When I used bellow code the error shown expect is not defined (inside of then )
Documentation link
it("should return error", function () {
return request(app).get("/verify")
.expect(200)
.then(function (res) {
return expect(res.body.error[0].message).to.equal("NEW_CODE_REQUIRED");
});
});
how can I check this?
Upvotes: 2
Views: 2269
Reputation: 16805
I solved it by following process. Added a function to check expected error that return error if got unexpected value and this function called from .expect()
function checkErrorMessage(res) { // this function throw error if got unexpected result
if(res.body.error[0].message === 'NEW_CODE_REQUIRED') {
return false; // return false means no error (got expected result)
} else {
return true; // return true means return error (got unexpected result)
}
}
it("should return error", function () {
return request(app).get("/verify")
.expect(200)
.expect(checkErrorMessage);
});
Upvotes: 0
Reputation: 203554
It's a bit of an oversight of the documentation not to mention that a standalone expect
function isn't included in the package.
For that, you have to use a separate package, like chai
:
const expect = require('chai').expect;
...
Upvotes: 2