Mocha is bailing when before() method in one describe() fails. ???

212 views
Skip to first unread message

Colin May

unread,
Jan 15, 2014, 4:38:45 PM1/15/14
to moc...@googlegroups.com
I have a test suite something like the following (assume all variables etc. have been defined):

describe("Feature1", function(){

    before(function(done){
        return browser
            .get(BASE_URL)
            .waitForElementByCss(ui.login.submitButton)
            .nodeify(done);
    });

    it("does stuff", function(done){
        ...
    });

    it("does other stuff", function(done){
        ...
    });
});

describe("Feature2", function(){
    it("does stuff", function(done){
        ...
    });
});

Although the bail option is properly set to false, Mocha shuts down and reports out immediately if that before() method fails. The second describe() suite never gets run.

Note that I am using mocha-as-promised, which might or might not be involved in the problem.

Anyone have ideas how I can make sure subsequent, separate tests get run even if a before()  fails?

Colin May

unread,
Jan 16, 2014, 2:34:55 PM1/16/14
to moc...@googlegroups.com
Update: Apparently I'm a fool, as mocha/lib/runner.js commentary for Runner.prototype.failHook states clearly, 

Hook failures (currently) hard-end due to that fact that a failing hook will surely cause subsequent tests to fail, causing jumbled reporting.

I disagree with that reasoning—I believe that in the absence of a bail flag the suite containing the before() or setup() should immediately fail all its tests and then the next suite should be executed. But I suppose that's a matter for the project's Issues forum. 

BTW, I posted this same stuff to Stack Overflow, so if you see it in both places, don't be shocked.
Reply all
Reply to author
Forward
0 new messages