When running jasmine tests, how can I find out if I am in the block being described, before each block or block?

I need to throw an exception if the utility is used outside the "it" or "beforeEach" block in my tests. Example -

   describe('some test', function(){

     useUtil();     // should throw exception

     beforeEach(function(){
        useUtil()   // should work
     })

     it('should test something', function(){
        useUtil()   // should work
     }) 
   })

The utility creates spies, and I want to make sure that they are created in such a way that allows Jasmine to clean them after each set.

+4
source share
1 answer

You can create a globally accessible variable with the name isSpecPhaseand set it to first false.

Then define the global beforeEach value:

beforeEach(function () {
    isSpecPhase = true;
});

beforeEach , . , isSpecPhase === true, .

+2

All Articles