You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Asynchronous code
Testing asynchronous code with Mocha could not be simpler! Simply invoke the callback when your test is complete. By adding a callback (usually named done) to it() Mocha will know that it should wait for completion.
describe('User', function(){
describe('#save()', function(){
it('should save without error', function(done){
var user = new User('Luna');
user.save(function(err){
if (err) throw err;
done();
});
})
})
})
Just thinking if (err) throw err; should be if (err) throw done(err);, right?
(PS: Can't find the correct file to create a pull request)
The text was updated successfully, but these errors were encountered:
It should work either way: you can let Mocha catch the error that you are throwing asynchronously, or you can pass the error directly to the done callback.
http://mochajs.org/#asynchronous-code
Just thinking
if (err) throw err;
should beif (err) throw done(err);
, right?(PS: Can't find the correct file to create a pull request)
The text was updated successfully, but these errors were encountered: