Mocha beforeEach vs before execution

后端 未结 4 1225
死守一世寂寞
死守一世寂寞 2020-12-24 04:42

I ran into a problem recently that I can\'t explain. I have alot of code in these tests so I\'m going to do my best to capture the idea here

I have tests that look li

4条回答
  •  清酒与你
    2020-12-24 05:41

    Mocha's test runner explains this functionality the best in the Hooks section of the Mocha Test Runner.

    From the Hooks section:

    describe('hooks', function() {
    
        before(function() {
            // runs before all tests in this file regardless where this line is defined.
        });
    
        after(function() {
            // runs after all tests in this file
        });
    
        beforeEach(function() {
            // runs before each test in this block
        });
    
        afterEach(function() {
            // runs after each test in this block
        });
    
        // test cases
    });
    

    You can nest these routines within other describe blocks which can also have before/beforeEach routines.

提交回复
热议问题