I have a db.js set up to do all my database calls. This is an example of one of the functions that query the database.
db.getUserCount = function () {
return new Promise (function (resolve, reject) {
db.users.count().then(function (result) {
resolve (result);
}, function(e) {
reject (e);
});
});
};
I am pretty new to JavaScript and testing. I have used mocha and chai to test that it resolves like this:
describe('getUserCount', function() {
it('should be fulfilled when called', function() {
return db.getUserCount().should.be.fulfilled;
});
});
How can I test the reject part of the promises. Do I have to use something like sinon or is there some simple way to make the promise fail?
I ended up using sinon stubs so the other test would still pass.
Make
db.users.count()
call to fail by either causing some change in database entry or in your api.