diff --git a/lib/runner.js b/lib/runner.js index ba4d7df97c..86bd4dc4af 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -302,7 +302,13 @@ Runner.prototype.hook = function(name, fn) { } if (err) { if (err instanceof Pending) { - suite.pending = true; + if (name === 'beforeEach' || name === 'afterEach') { + self.test.pending = true; + } else { + suite.tests.forEach(function(test) { + test.pending = true; + }); + } } else { self.failHook(hook, err); @@ -516,7 +522,7 @@ Runner.prototype.runTests = function(suite, fn) { // execute test and hook(s) self.emit('test', self.test = test); self.hookDown('beforeEach', function(err, errSuite) { - if (suite.isPending()) { + if (test.isPending()) { self.emit('pending', test); self.emit('test end', test); return next(); @@ -843,8 +849,8 @@ function filterLeaks(ok, globals) { } // in firefox - // if runner runs in an iframe, this iframe's window.getInterface method not init at first - // it is assigned in some seconds + // if runner runs in an iframe, this iframe's window.getInterface method + // not init at first it is assigned in some seconds if (global.navigator && (/^getInterface/).test(key)) { return false; } diff --git a/test/integration/regression.js b/test/integration/regression.js index f20f601ea1..b8c64b84e7 100644 --- a/test/integration/regression.js +++ b/test/integration/regression.js @@ -1,4 +1,4 @@ -var assert = require('assert'); +var assert = require('assert'); var fs = require('fs'); var path = require('path'); var run = require('./helpers').runMocha; @@ -50,4 +50,16 @@ describe('regressions', function() { done(); }); }) + + describe('issue-2286: after doesn\'t execute if test was skipped in beforeEach', function () { + var afterWasRun = false; + describe('suite with skipped test for meta test', function () { + beforeEach(function () { this.skip(); }); + after(function () { afterWasRun = true; }); + it('should be pending', function () {}); + }) + after('meta test', function () { + afterWasRun.should.be.ok(); + }); + }); });