有没有办法只针对某些测试('它'块)执行beforeEach功能。假设我有10个块,我不希望beforeEach为两个块执行。有可能吗?
答案 0 :(得分:10)
您可以将您希望在之前运行的规范分组到单独的describe
:
it('should 1...', function () {});
it('should 2...', function () {});
describe('group', function () {
beforeEach(function () {
// ...
});
it('should 3...', function () {});
it('should 4...', function () {});
// ...
});
答案 1 :(得分:0)
我目前通过以下方式解决了这个问题:
var executeBeforeEach = true;
function beforeEach() {
if(!executeBeforeEach) return;
//your before each code here.
}
describe('some test case 1', function(){
it('Start', function(){
//this is a dummy block to disable beforeeach for next test
})
it('The test that does not need beforeEach', function(){
//this test does not need before each.
})
it('Start', function(){
//this is a dummy block to enable beforeeach for next test
})
})
但是,我想知道是否有更优雅的方式!?!