Jasmine避免在每次进行某些测试之前

Ane*_*esh 6 jasmine

有没有办法不执行beforeEach函数只对某些测试('它'块).假设我有10个块,我不希望beforeEach为两个块执行.可能吗?

Mic*_*nov 11

您可以将beforeEach之前要运行的规范分组到一个单独的describe:

it('should 1...', function () {});
it('should 2...', function () {});

describe('group', function () {

    beforeEach(function () {
        // ...
    });

    it('should 3...', function () {});
    it('should 4...', function () {});

    // ...
});
Run Code Online (Sandbox Code Playgroud)

  • 你的意思是你想要在`describe`中的所有规范之前执行一次代码吗?在这种情况下,[`beforeAll`](http://jasmine.github.io/2.1/introduction.html#section-Setup_and_Teardown)可以提供帮助. (2认同)