Mocha: Setting message (reason) for test skip

Created on 3 Nov 2016  路  8Comments  路  Source: mochajs/mocha

Is it possible to set a message (mentioning reason) why a particular test is skipped, so that it could be used in reporters.

describe('xxx', function() {
 checkToSkip(1)("test1", function() {\*test goes here*\});
 checkToSkip(4)("test2", function() {\*test goes here*\});
});

function checkToSkip(now) {
    return now > 3 ? it : xit; 
   //return now > 3 ? it : it.skip; 
}

Here 'test1' will be skipped as 'checkToSkip' returns 'xit' (or it.skip). Is it possible to pass a message to reporter mentioning the reason for the test skip? something like below (or any other possible way).

checkToSkip(4)("test2", function() { \\ test goes here}, "My Skip message!!!!" );

or

checkToSkip(4)("test2", function() { \\ test goes here}).pending("My Skip message!!!!");

Note: Im using mocha in webdriverIO.

Thanks.

feature usability

Most helpful comment

One approach that could cover all use cases and would only be a small api change would be to allow an optional reason parameter to this.skip(). The it.skip(...) case could be satisfied by just calling this.skip("reason") in the first line of the test.

All 8 comments

http://stackoverflow.com/questions/31688650/is-it-possible-to-send-a-reason-for-jasmine-2-specs-skipped-with-xit-or-pending

This thread explains the solution for same problem using Jasmine. Im looking for something similar in Mocha.

I too would love to have something like that.

I could not find any inputs about how to enter reason for skipping in documentation here

May be a candidate for a feature request? It could just be a case that the documentation is missing while feature is there.

this would be a good usability improvement, but see @ponmudivn's workaround

One approach that could cover all use cases and would only be a small api change would be to allow an optional reason parameter to this.skip(). The it.skip(...) case could be satisfied by just calling this.skip("reason") in the first line of the test.

Agreed with @jeffvandyke I would love to have this feature

How about doing:

    it.skip("A test").reason("Code has changed");

But that doesn't allow for using the this.skip api, so maybe it can also accept a second or third string parameter as the reason as well. But that just seems weird in my opinion.

duplicate of #2026

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Swivelgames picture Swivelgames  路  3Comments

eschwartz picture eschwartz  路  3Comments

smithamax picture smithamax  路  4Comments

niftylettuce picture niftylettuce  路  3Comments

danielserrao picture danielserrao  路  3Comments