I am trying to test a piece of code I wrote with bluebird promises, by using chai-as-promised.
My method to be tested returns a promise rejection, as follows:
/**
* Creates a new user entry in the database.
* @param {JSONObject} userData -- User details for creation.
* @return => {boolean} true if succefully created, false otherwise.
**/
createUser: function(userData) {
return Promise.reject();
},
The testing code is as this:
describe('User creation test suite', function() {
it('Should successfully create root user', function(done) {
expect(users.createUser(sampleUsers.raam))
.to.eventually.have.property('id').and.notify(done);
//expect(Promise.resolve({foo:'bar'})).to.eventually.have.property('id').and.notify(done);
});
Eventhough, the method is intentionally failing, but the testcase is being marked as passed. Here is the output.
User creation test suite
✓ Should successfully create root user
If I test directly with a hardcoded string like
expect(Promise.resolve({foo:'bar'})).to.eventually.have.property('id').and.notify(done);
Then it seems to work. What am I doing wrong here?
EDIT I found that it had nothing todo with bluebird promises or my method which is under test. A simple hardcoded rejection also doesn't work correctly. That is...,
expect(Promise.reject({foo:'bar'})).to.eventually.have.property('id').and.notify(done)
returns as passed, instead of failing. Am I doing something terribly wrong here?