Reputation: 12890
I have some code below:
const assert = require('assert')
describe('server', function() {
before(function() {
// HACK: skip the tests in staging environment until we find to provide db in it
if(process.env.NODE_ENV === 'staging') {
this.skip();
}
});
it('list request', function() {
assert.fail('fails wo db')
})
describe('detail requests', function() {
it('some arguments', function() {
assert.fail('fails wo db')
})
})
})
When I run NODE_ENV='staging' npm test
:
> @ test /Users/kharandz/Projects/mocha-bug
> mocha
server
- list request
detail requests
1) some arguments
0 passing (10ms)
1 pending
1 failing
1) server detail requests some arguments:
AssertionError: 'fails wo db' undefined undefined
at Context.<anonymous> (test/sample.spec.js:16:14)
But I expect that all the tests are skipped. So, the question:
Upvotes: 5
Views: 2986
Reputation: 32848
It appears it's not supported by Mocha, and it's considered a "feature".
See: https://github.com/mochajs/mocha/issues/2683
Can be workaround by
before(function () {
this.test.parent.pending = true;
this.skip();
});
Upvotes: 3