☕️ Classic, reliable, trusted test framework for Node.js and the browser
JSON error objects for debugging. Add two tests for invoking done() with non-Errors
Panu Horsmalahti05c5df2c8e46
diff --git a/lib/runnable.js b/lib/runnable.jsindex db8d014c..388b1f31 100644--- a/lib/runnable.js+++ b/lib/runnable.js@@ -213,7 +213,13 @@ Runnable.prototype.run = function(fn){try {this.fn.call(ctx, function(err){if (err instanceof Error || toString.call(err) === "[object Error]") return done(err);- if (null != err) return done(new Error('done() invoked with non-Error: ' + err));+ if (null != err) {+ if (Object.prototype.toString.call(err) === '[object Object]') {+ return done(new Error('done() invoked with non-Error: ' + JSON.stringify(err)));+ } else {+ return done(new Error('done() invoked with non-Error: ' + err));+ }+ }done();});} catch (err) {diff --git a/test/runnable.js b/test/runnable.jsindex 5fa9352f..ee20c8a5 100644--- a/test/runnable.js+++ b/test/runnable.js@@ -241,6 +241,32 @@ describe('Runnable(title, fn)', function(){})})+ describe('when done() is invoked with a non-Error object', function(){+ it('should invoke the callback', function(done){+ var test = new Runnable('foo', function(done){+ done({ error: 'Test error' });+ });++ test.run(function(err){+ err.message.should.equal('done() invoked with non-Error: {"error":"Test error"}');+ done();+ });+ })+ })++ describe('when done() is invoked with a string', function(){+ it('should invoke the callback', function(done){+ var test = new Runnable('foo', function(done){+ done('Test error');+ });++ test.run(function(err){+ err.message.should.equal('done() invoked with non-Error: Test error');+ done();+ });+ })+ })+it('should allow updating the timeout', function(done){var callCount = 0;var increment = function() {