visionmedia/mocha — pull request #889 by juandopazo (2013-06-05 23:47:00+00:00)
Title: Add resume() for async tests that trap exceptions

Hi!

Mocha's async support is awesome, but it as a small deficiency for testing code that catches exceptions, most notably promise-based code or code using [task.js](http://taskjs.org/). For example:

```javascript
it('should show the correct assertion failure', function (done) {
somePromise.then(function (value) {
// since then() catches exceptions here
// when the test passes everything is ok
// but when the assertion fails
// the test doesn't report the assertion failure
expect(value).to.be(5);
done();
})
})
```
This pull request introduces a helper function hidden as a property of the `done` callback that catches its own exceptions and concludes the test the same way as `done`. This would let us use the following pattern:
```javascript
it('should show the correct assertion failure', function (then) {
somePromise.then(function (value) {
then.resume(function () {
expect(value).to.be(5);
});
})
})
```
I would be very much OK with other names for `resume` like `next`, or a second callback if you think it would be a better choice.