Mocha beforeEach vs before execution

后端 未结 4 1227
死守一世寂寞
死守一世寂寞 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:25

    I found a similar issue. The documentation is misleading because "before this block" means (to me at least) "before this describe section". Meanwhile it means "before any describe section". Check this example:

    describe('outer describe', function () {
        beforeEach(function () {
            console.log('outer describe - beforeEach');
        });
    
        describe('inner describe 1', function () {
            before(function () {
                console.log('inner describe 1 - before');
            });
    
        describe('inner describe 2', function () {
            beforeEach(function () {
                console.log('inner describe 2 - beforeEach');
            });
     });
    
     // output will be:
     // inner describe 1 - before
     // outer describe - beforeEach
     // inner describe 2 - beforeEach
    

    It seems it doesn't matter where in your hierarchy you put the before - it will run before any describe and not before its containing describe.

提交回复
热议问题