Mocha: Ability to skip tests in beforeEach

Created on 7 May 2014  路  4Comments  路  Source: mochajs/mocha

We have a bunch of tests that we only run optionally based on the environment, we use various ways to do if (build time flags, just putting tests inside an if), but the best place for us to do it would be inside beforeEach, it would be nice if there was a way to provide something to done that indicated the test should be skipped

Can try coming up with a patch if that seems like something likely to be merged?

Most helpful comment

For anyone finding this issue: this little snippet of code should help you work around the issue:

beforeEach(function()
{
  if (YOUR_CONDITION_HERE) this.currentTest.fn = function() { this.skip(); }
});

All 4 comments

I would also like to know how to do this. I played with it. If I throw an error, it stops all test execution. If I set the this.currentTest.pending flag to true, it still executes the test.

332

For anyone finding this issue: this little snippet of code should help you work around the issue:

beforeEach(function()
{
  if (YOUR_CONDITION_HERE) this.currentTest.fn = function() { this.skip(); }
});

you can also just use this.skip ie

beforeEach(function() {
  if (FAILED_TESTS[this.currentTest.file]) {
    this.skip();
  }
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

quangv picture quangv  路  38Comments

ibc picture ibc  路  59Comments

boneskull picture boneskull  路  76Comments

KylePDavis picture KylePDavis  路  71Comments

sagiegurari picture sagiegurari  路  61Comments