Based on the documentation:
To skip multiple tests in this manner, use
this.skip()in a “before” hook
I expected the test below to never run.
describe('skip', function() {
before(function() {
this.skip();
});
describe('bug', function() {
it('should never be called', function() {
throw new Error('Why is this reached?');
});
});
});
However, here is the output.
✗ mocha bug.js
skip
bug
1) should never be called
0 passing (7ms)
1 failing
1) skip bug should never be called:
Error: Why is this reached?
at Context.<anonymous> (bug.js:8:19)
This seems like a bug to me. If it is expected behavior, then the documentation should be updated to reflect this.
@fearphage I'm able to reproduce this with Mocha v3.4.2. It appears that calling this.skip() doesn't work correctly for nested suites. 😕
I've come across this issue as well. [email protected]
Just ran into this issue as well in v4.0.1
ran into this issue too, any process?
cc @Munter @boneskull
I see this behavior too. I'm pretty sure it's a bug that was introduced at some point between late 2016 and the date that this thread was opened. I've been editing some tests that skipped correctly when I looked at them a year ago and now aren't being skipped.
5.0.4, ran into this issue too
I suspect there is something being mis-handled with "current test" and before resolution. This feels like it may be a different symptom of the problem underlying #2134
I confirm I have this bug as well
Yet another confirmation post. Is anyone going to get on this?
Looking at the number of open issues, it's doubtful :)
I have worked around this by setting a scoped skipping variable true if skipping, and then checking that in a before function in each subsuite. It's not pretty, but it's a nice chance to link to this issue :)
describe('outer', function() {
let skipping = false;
before(function() {
if (...) {
this.pending = 1;
skipping = 1;
}
});
describe('inner', function() {
// work around https://github.com/mochajs/mocha/issues/2819
before(function() {
if (skipping) {
this.pending = 1;
}
});
});
});
There is a simpler workaround imo, using beforeEach instead:
beforeEach(function() {
if (skipping) this.skip()
})
The workaround in https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 worked for me with [email protected]
@fearphage I think the fix for this has now gone into master (via #3225). Closing this issue.
Most helpful comment
The workaround in https://github.com/mochajs/mocha/issues/2683#issuecomment-375629901 worked for me with
[email protected]