diff --git a/lib/runnable.js b/lib/runnable.js index 6e4803fd7f..7883ef49c8 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -196,6 +196,10 @@ Runnable.prototype.run = function(fn){ , finished , emitted; + // Runner expects to catch an instance of Pending if a pending test is ran + if (this.pending) + throw new Pending(); + // Some times the ctx exists but it is not runnable if (ctx && ctx.runnable) ctx.runnable(this); @@ -253,11 +257,7 @@ Runnable.prototype.run = function(fn){ // sync or promise-returning try { - if (this.pending) { - done(); - } else { - callFn(this.fn); - } + callFn(this.fn); } catch (err) { done(utils.getError(err)); } diff --git a/test/runner.js b/test/runner.js index a2ce512514..dd50540149 100644 --- a/test/runner.js +++ b/test/runner.js @@ -337,4 +337,39 @@ describe('Runner', function(){ }); }); }); + + describe('.run', function(){ + it('should emit "pending" for each pending test', function(done){ + var pendingCount = 0; + + var pendingTest = new Test('a pending test', function (){}); + pendingTest.pending = true; + + var skippedTest = new Test('a test that will be skipped', function(){ + this.skip(); + }); + + var otherPendingTest = new Test('a test that will be marked as pending', + function(){}); + + suite.addTest(pendingTest); + suite.addTest(skippedTest); + suite.addTest(otherPendingTest); + + runner.on('test', function (test) { + if (test === otherPendingTest) + otherPendingTest.pending = true; + }); + + runner.on('pending', function () { + pendingCount++; + }); + + runner.run(function (){ + pendingCount.should.equal(3); + done(); + }); + }) + }) + });