mocha pass variable to the next test

后端 未结 3 1422
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 15:42
describe(\'some test\', function(){
    // Could put here a shared variable
    it(\'should pass a value\', function(done){
        done(null, 1);
    });
    it(\'a         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 16:33

    Very much agree with what Louis said, and those are the reasons that Mocha doesn't actually support it. Think of the async method you referenced; if your first test fails you get a waterfall failure across the rest of them.

    Your only way to go about it is, as you say, to stick a variable at the top:

    describe('some test', function(){
        var value = 0;
        it('should pass a value', function(done){
            value = 5;
            done();
        });
        it('and then double it', function(done){
            console.log(value * 2); // 10
            done();
        });
    });
    

提交回复
热议问题