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.
You can create a globally accessible variable with the name isSpecPhaseand set it to first false.
isSpecPhase
false
Then define the global beforeEach value:
beforeEach(function () { isSpecPhase = true; });
beforeEach , . , isSpecPhase === true, .
beforeEach
isSpecPhase === true