Declare "pending" specs/tests in jasmine or mocha

24,283

Solution 1

You can declare disabled functions in both mocha and jasmine using xit (instead of it), and xdescribe (instead of describe).

If you want the tests to appear as pending, in mocha you can just leave the second parameter blank in the call to the it() function. For example:

describe('Something', function () {
    it('Should be pending')
    xit('Should be disabled, i.e not appear on the list')
});

Update: The behaviour for xit/xdescribe is might change in Mocha if this merge happens: https://github.com/visionmedia/mocha/pull/510

Solution 2

Starting with Jasmine 2.0, writing xit() instead of it() for a spec marks it as pending (as already said in a comment of the accepted answer).

Aditionally, there is a pending() function you can call anywhere inside a spec to mark it as pending:

it("can be declared by calling 'pending' in the spec body", function() {
  expect(true).toBe(false);
  pending();
});

See also the documentation on pending specs in Jasmine 2.0.

Solution 3

In mocha, you can also use skip:

describe('my module', function() {
  it.skip('works', function() {
    // nothing yet
  });
});

You can also do describe.skip to skip whole sections.

Share:
24,283
WHITECOLOR
Author by

WHITECOLOR

Updated on March 02, 2020

Comments

  • WHITECOLOR
    WHITECOLOR over 4 years

    I would like to describe specifications that should be in the code, but implementation of them would be added later. In test results I would like to see them neither passed nor failed, but "are waiting" for implementation instead.

    I'm interested if it is possible to do out of the box in mocha or jasmine.

    Thanks

  • WHITECOLOR
    WHITECOLOR almost 12 years
    Thank you. So now xit don't show it in report, and after the merge it will, if I got it right? Actually I would like to see them in the report.
  • Admin
    Admin almost 12 years
    If you want them to show in the report currently, I suggest using it() without the second parameter (the test function). The test runner will then mark it as pending.
  • Len
    Len over 11 years
    how does the test runner mark them as pending? AFAIK, jasmine shows them as a 'pass'?
  • alxndr
    alxndr over 10 years
    [in Jasmine 1.5] it() with no second parameter shows up as a pass, which I would not consider pending. xit() and xdescribe() (latter needs a function second param) aren't pending; they're completely ignored and not mentioned in the UI. this.fail('message'); will manually fail a test; also not pending. Jasmine v2 will apparently have a true "pending" state.
  • Jerry Joseph
    Jerry Joseph about 7 years
    describe.skip() and it.skip() is much cleaner than xdescribe and xit
  • GreensterRox
    GreensterRox almost 6 years
    pending("This is the reason why it is pending");