Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
this.skip() in before fails to skip tests with nested describe calls
  • Loading branch information
Elergy committed May 27, 2017
1 parent 99b282b commit 5267c53
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/runnable.js
Expand Up @@ -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.
*
Expand Down
10 changes: 4 additions & 6 deletions lib/runner.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions lib/suite.js
Expand Up @@ -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.
*
Expand Down
30 changes: 30 additions & 0 deletions test/acceptance/interfaces/bdd.spec.js
Expand Up @@ -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);
});
});
});

0 comments on commit 5267c53

Please sign in to comment.