If I comment the line return Promise.reject(err);
in my findGood
function, the test case should fail. Meaning that, if I'm not returning from my function, the catch
block in the test should be undefined
.
var findGood = function (name) {
return goodModel.findByName(name)
.then( (result) => {
....
return result;
})
.catch( (err) => {
return Promise.reject(err);
});
};
Here is a test
it('good not found', function () {
var goodModelStub = sinon.stub(goodModel, 'findByName');
var error = 'Good not found';
goodModelStub.returns(Promise.reject(error));
return goodFinder.findGood('Sony')
.catch(function (err) {
assert.equal(err, error);
});
});