mocha - How to skip the afterEach hook if the current test case fails and continue to run the next test case after? -


describe("test1", function() {   before("at start", function() {    console.log("at begining of test case");    setup();   }    beforeeach("before test case", function() {    console.log("at begining of test case");    testsetup();   }    aftereach("at end of test case", function() {    console.log("at end of test case");    cleanup();   }    after("at end of test", function() {    console.log("at end of test");    commoncleanup();   }    it("test case1", function() {    var retval = sum(2,5);    assert.equal(retval, "then sum 5");   }    it("test case2", function() {    var retval = sum(5,5);    assert.equal(retval, "the sum 10");   } }); 

if beforeeach code fails or throws error, continues test case1 , aftereach hook. want if beforeeach fails should skip test case1 , aftereach hook, continue run test case2 , aftereach hook. mean if hook fails should skip current test case , continue run next test cases. want expected output be:

test1 @ beginning of test case before test case x beforeeach hook fails before test case test case2  @ end of test case @ end of test 1 passing (8ms) 1 failing (0ms) 

please me find solution this.

you can use this.currenttest.state (not sure when introduced):

aftereach(function() {   if (this.currenttest.state == 'failed') {     // ...   } }); 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -