diff --git a/lib/runnable.js b/lib/runnable.js index ee8c4a3467..f3b980723c 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -147,6 +147,14 @@ Runnable.prototype.isPending = function () { return this.pending || (this.parent && this.parent.isPending()); }; +/** + * Mark the runnable as pending or not pending + * @param pending + */ +Runnable.prototype.setPending = function (pending) { + this.pending = pending; +}; + /** * Set number of retries. * diff --git a/lib/runner.js b/lib/runner.js index b024e0dcb5..d195d56af8 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -314,13 +314,11 @@ Runner.prototype.hook = function (name, fn) { if (err) { if (err instanceof Pending) { if (name === 'beforeEach' || name === 'afterEach') { - self.test.pending = true; + self.test.setPending(true); } else { - utils.forEach(suite.tests, function (test) { - test.pending = true; - }); + suite.setPending(true); // a pending hook won't be executed twice. - hook.pending = true; + hook.setPending(true); } } else { self.failHook(hook, err); @@ -551,7 +549,7 @@ Runner.prototype.runTests = function (suite, fn) { if (err) { var retry = test.currentRetry(); if (err instanceof Pending) { - test.pending = true; + test.setPending(true); self.emit('pending', test); } else if (retry < test.retries()) { var clonedTest = test.clone(); diff --git a/lib/suite.js b/lib/suite.js index 13617ab91d..af65f62a47 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -189,6 +189,14 @@ Suite.prototype.isPending = function () { return this.pending || (this.parent && this.parent.isPending()); }; +/** + * Mark the suite as pending or not pending + * @param pending + */ +Suite.prototype.setPending = function (pending) { + this.pending = pending; +}; + /** * Run `fn(test[, done])` before running tests. * diff --git a/test/acceptance/interfaces/bdd.spec.js b/test/acceptance/interfaces/bdd.spec.js index f6e24d88a8..fc48215a00 100644 --- a/test/acceptance/interfaces/bdd.spec.js +++ b/test/acceptance/interfaces/bdd.spec.js @@ -32,3 +32,33 @@ context('test suite', function () { expect(this.number).to.equal(5); }); }); + +describe('a suite skipped by "before" hook', function () { + before(function () { + this.skip(); + }); + + it('should skip this test', function () { + expect(2).to.equal(1); + }); + + it('should skip this test too', function () { + expect(2).to.equal(1); + }); +}); + +describe('a parent suite with "skip" in "before" hook', function () { + before(function () { + this.skip(); + }); + + describe('a suite skipped by parent\'s "before" hook', function () { + it('should skip this test', function () { + expect(2).to.equal(1); + }); + + it('should skip this test too', function () { + expect(2).to.equal(1); + }); + }); +});