Skip to content

Commit

Permalink
fix this.skip() in beforeEach hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Dec 21, 2019
1 parent d9f5079 commit 0e2ba28
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/runner.js
Expand Up @@ -394,10 +394,17 @@ Runner.prototype.hook = function(name, fn) {
'Use a return statement or other means to abort hook execution.'
);
}
if (name === HOOK_TYPE_BEFORE_EACH || name === HOOK_TYPE_AFTER_EACH) {
if (name === HOOK_TYPE_AFTER_EACH) {
if (self.test) {
self.test.pending = true;
}
} else if (name === HOOK_TYPE_BEFORE_EACH) {
if (self.test) {
self.test.pending = true;
}
self.emit(constants.EVENT_HOOK_END, hook);
hook.pending = false; // activates hook for next test
return fn(new Error('abort hookDown'));
} else {
suite.tests.forEach(function(test) {
test.pending = true;
Expand Down Expand Up @@ -634,6 +641,7 @@ Runner.prototype.runTests = function(suite, fn) {
// execute test and hook(s)
self.emit(constants.EVENT_TEST_BEGIN, (self.test = test));
self.hookDown(HOOK_TYPE_BEFORE_EACH, function(err, errSuite) {
// conditional this.skip() within beforeEach()
if (test.isPending()) {
if (self.forbidPending) {
test.isPending = alwaysFalse;
Expand All @@ -643,15 +651,21 @@ Runner.prototype.runTests = function(suite, fn) {
self.emit(constants.EVENT_TEST_PENDING, test);
}
self.emit(constants.EVENT_TEST_END, test);
return next();
// skip afterEach hooks below errSuite level
var origSuite = self.suite;
self.suite = errSuite;
return self.hookUp(HOOK_TYPE_AFTER_EACH, function() {
self.suite = origSuite;
next();
});
}
if (err) {
return hookErr(err, errSuite, false);
}
self.currentRunnable = self.test;
self.runTest(function(err) {
test = self.test;
// conditional this.skip()
// conditional this.skip() within it()
if (test.pending) {
if (self.forbidPending) {
test.isPending = alwaysFalse;
Expand Down

0 comments on commit 0e2ba28

Please sign in to comment.