Skip to content

Commit

Permalink
Merge pull request #2287 from mochajs/skip-after-regression
Browse files Browse the repository at this point in the history
Add failing test: after hook is not run if test skipped in beforeEach; closes #2286
  • Loading branch information
boneskull committed Jun 11, 2016
2 parents e939d8e + d165c82 commit 8a37e01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/runner.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion 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;
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit 8a37e01

Please sign in to comment.