Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Added: allow done() to be called with non-Error

Tj Holowaychuk2024f8b5d33a
diff --git a/lib/runnable.js b/lib/runnable.js
index a3610332..3180bff2 100644
--- a/lib/runnable.js
+++ b/lib/runnable.js
@@ -102,7 +102,10 @@ Runnable.prototype.run = function(fn){
// async
if (this.async) {
try {
- this.fn(done);
+ this.fn(function(err){
+ if (err instanceof Error) return done(err);
+ done();
+ });
} catch (err) {
done(err);
}
diff --git a/test/runnable.js b/test/runnable.js
index e6881959..7a48fe32 100644
--- a/test/runnable.js
+++ b/test/runnable.js
@@ -1,6 +1,7 @@
var mocha = require('../')
- , Runnable = mocha.Runnable;
+ , Runnable = mocha.Runnable
+ , EventEmitter = require('events').EventEmitter;
describe('Runnable(title, fn)', function(){
describe('#timeout(ms)', function(){
@@ -90,6 +91,14 @@ describe('Runnable(title, fn)', function(){
})
})
+ describe('when the callback is invoked with a non-Error', function(){
+ it('should pass', function(done){
+ var thing = new EventEmitter;
+ thing.on('foo', done);
+ thing.emit('foo', 'bar');
+ })
+ })
+
describe('when the callback is invoked several times', function(){
describe('without an error', function(){
it('should emit a single "error" event', function(done){