0

I am writing Angular component unit testing using jasmine. We are having class with static variables which is initialized during loading time of application. Currently we are initializing those static variables in beforeAll of the unit test of component which uses those variable.

Calling the same initialization function in all the unit test files seems redundant.

Is there any way to initialize those static variables globally during the beginning of jasmine unit test which can be available to all the unit test suits ?

Currently we are initializing those static variable like this :

describe(('mycomponent'), () => {
  beforeAll(()=>{
   // call to initialize function
  });
});
scokmen
  • 571
  • 3
  • 19
Vignesh Pandi
  • 349
  • 1
  • 4
  • 15

1 Answers1

0

In my opinion, you should encapsulate the global variables with service and use this wrapper service in your component. In this way, you can mock this wrapper service easily.

For example:

class GlobalVariableService {
  public getXxx() {
    return window.Xxx;
  }
}
scokmen
  • 571
  • 3
  • 19