mocha pass variable to the next test

后端 未结 3 1430
没有蜡笔的小新
没有蜡笔的小新 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:17

    It is also possible to add to the suit or context object.

    In this example, It's added to the suit object

    describe('suit', function(){
        before(() => {
            this.suitData = 'suit';
        });
    
        beforeEach(() => {
            this.testData = 'test';
        });
    
    
        it('test', done => {
             console.log(this.suitData)// => suit
             console.log(this.testData)// => test
        })
    });
    

提交回复
热议问题