☕️ Classic, reliable, trusted test framework for Node.js and the browser
Throw a descriptive error when a non-function is given to a runnable (#4133)
Ziraka24683fd9273
diff --git a/lib/runnable.js b/lib/runnable.jsindex 2d0c428d..0346b363 100644--- a/lib/runnable.js+++ b/lib/runnable.js@@ -338,6 +338,15 @@ Runnable.prototype.run = function(fn) {// for .resetTimeout()this.callback = done;+ if (this.fn && typeof this.fn.call !== 'function') {+ done(+ new TypeError(+ 'A runnable must be passed a function as its second argument.'+ )+ );+ return;+ }+// explicit async with `done` argumentif (this.async) {this.resetTimeout();diff --git a/test/unit/runnable.spec.js b/test/unit/runnable.spec.jsindex 40ccc12c..2c079c3b 100644--- a/test/unit/runnable.spec.js+++ b/test/unit/runnable.spec.js@@ -670,6 +670,20 @@ describe('Runnable(title, fn)', function() {});});});++ describe('when fn is not a function', function() {+ it('should throw an error', function() {+ var runnable = new Runnable('foo', 4);++ runnable.run(function(err) {+ expect(+ err.message,+ 'to be',+ 'A runnable must be passed a function as its second argument.'+ );+ });+ });+ });});describe('#isFailed()', function() {