Skip to content

Instantly share code, notes, and snippets.

@thanpolas
Created April 11, 2013 22:00
Show Gist options
  • Save thanpolas/5367556 to your computer and use it in GitHub Desktop.
Save thanpolas/5367556 to your computer and use it in GitHub Desktop.
Testing promises with mocha
var assert = require('chai').assert;
var when = require('when');
var def1 = when.defer();
function getProm() {
return def1.promise;
}
suite('Test a promise', function() {
test('an async test with a promise', function(done){
function onResolve(val) {
assert.equal('bar', val, 'Value should be "bar"');
done();
}
// the trick is the final .otherwise that will catch
// the error thrown in the 'onResolve' function
getProm().then(onResolve, done).otherwise(done);
});
});
def1.resolve('foo');
@ORESoftware
Copy link

wouldnt be cool to adopt the given-when-then of BDD into mocha with something like this:

it('test', function(){

return given().when().then()

});

does anybody know what I am talking about?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment