How should I be testing, with mocha and chai, that my promise has failed?
I am confused, because I initially thought I should be using 'mocha-as-promised', but that package is now deprecated (I'm using mocha 2.1.0), with the advice to just use the promise testing that's now built into mocha. see: https://github.com/domenic/mocha-as-promised
Another post recommends doing away with the 'done' argument to the it() callback - not sure I understand why, since my understanding that passing in the 'done' parameter was the way to signal that a test was being tested asynchronously. see: How do I properly test promises with mocha and chai?
Anyway, I've tried to reduce my issue to the below code - please help me modify this so that I can test that my promise indeed fails.
it.only("do something (negative test)", function (done) {
var Q = require('q');
function makePromise() {
var deferred = Q.defer();
deferred.reject(Error('fail'));
return deferred.promise;
};
makePromise()
.then(done, done);
});