Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2819 - this.skip() in before fails to skip tests with nested describe calls #2836

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/runnable.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all the failure cases, you should call fail directly: expect().to.fail('message here')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

});

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);
});
});
});