mercredi 25 février 2015

testing failed promises with mocha's built-in promise support

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: http://ift.tt/OZTbha


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 to 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);

});

Aucun commentaire:

Enregistrer un commentaire