javascript - How can you avoid prevent a beforeEach from running before one particular it block? -


describe('1', function () {   beforeeach(function () {     // before each except 1.5   });   it('1.1', function () {    });   it('1.2', function () {    });   it('1.3', function () {    });   it('1.4', function () {    });   it('1.5', function () {     // beforeeach shouldn't run before   }); }); 

i'd prevent beforeeach running before it block 1.5. how can that?

option 1

i suggest using nesting describes, e.g.:

describe('1', function () {    describe('1 4', function () {      beforeeach(function () {       // before each except 1.5     });     it('1.1', function () {      });     it('1.2', function () {      });     it('1.3', function () {      });     it('1.4', function () {      });   });    describe('only 5', function () {      it('1.5', function () {      // beforeeach shouldn't run before   });  }); 

behind scenes describe register beforeeach function called itfunctions if exists.


option 2

the it functions called sequentially use closure control when beforeeach gets run - it's bit hacky - e.g.:

describe('1', function () {   var runbefore = true   beforeeach(function () {     // before each except 1.5     if (runbefore) {         // actual code     }   });   // functions removed brevity       it('1.4', function () {       runbefore = false;   });   it('1.5', function () {     // beforeeach shouldn't run before      // turn on 1.6     runbefore = true;   }); }); 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -