Mocha: Question: Allow failures?

Created on 21 Aug 2016  路  8Comments  路  Source: mochajs/mocha

Is there a way to allow the failure of specific tests but show that they are failing?

needs-feedback question stale

Most helpful comment

Here is a simplified workaround

it.allowFail = (title, callback) => {
  it(title, function() {
    return Promise.resolve().then(() => {
      return callback.apply(this, arguments);
    }).catch(() => {
      this.skip();
    });
  });
};

it.allowFail('skip on error', function() {
  assert.ok(false);
});

or use it here if you want.

All 8 comments

By "allow" you mean what, exactly?

@boneskull Like jasmine, it has a "fail" function,

describe("A spec using the fail function", function() {
  var foo = function(x, callBack) {
    if (x) {
      callBack();
    }
  };

  it("should not call the callBack", function() {
    foo(false, function() {
      fail("Callback has been called");
    });
  });
});

Exactly!

@boneskull This section in the ava docs describes a huge benefit that comes with this: a PR with a failing test (but a failing test that doesn't break the build).

I'm currently using it.skip in a few cases where there are known bugs and we have a failing test case, but it's not a high enough priority for an immediate fix. This doesn't actually run the failing test though and doesn't differentiate between an unwritten pending test and a known failing test.

It would be great to see something like:

441 passing (509ms)
3 pending
1 expected failing

Also, I wouldn't be able to take this on immediately, but if you'd be willing to merge a PR that implemented this, I would be willing to work on this in the near future.

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

Here is a simplified workaround

it.allowFail = (title, callback) => {
  it(title, function() {
    return Promise.resolve().then(() => {
      return callback.apply(this, arguments);
    }).catch(() => {
      this.skip();
    });
  });
};

it.allowFail('skip on error', function() {
  assert.ok(false);
});

or use it here if you want.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Swivelgames picture Swivelgames  路  3Comments

robertherber picture robertherber  路  3Comments

Aarbel picture Aarbel  路  3Comments

juergba picture juergba  路  3Comments

3p3r picture 3p3r  路  3Comments