I need to test this function :
//user.js
function getUser(req, res, next){
helper.get_user(param1, param2, (err, file) => {
if (err) return next(err);
}
This is my test function :
it ("failed - helper.get_user throws error", sinon.test(function () {
var req, res;
var get_user = this.stub(helper, "get_user")
get_user.yields(new Error("message"));
var next = sinon.spy(next);
user.get_user(req, res, next);
expect(next).to.have.been.calledWith(new Error("other message"));
}))
For my assertion I'm using sinon-chai syntax.
This test is passing even though I would expect it to fail, because my code doesn't throw a message with the error.
How can I test that an error is thrown with correct message?