How to Globally Register Injection Tokens in Angular TestBed
The article discusses the problem of registering Injection Tokens at a global level in the Angular TestBed. It explains that while registering tokens at the component level is taken care of automatically, registering global tokens can become repetitive and cumbersome. The author suggests a solution to this problem by adding the token to the global test setup file using TestBed.overrideProvider. This allows developers to set the value of the token once for all tests. However, the drawback is that it sets the value for all tests, making it less intuitive to override for specific tests. The ideal solution proposed is to set the injection token for one-off cases using the providers array when configuring the TestBed. This approach provides more flexibility and avoids the need to know which token is registered globally. Overall, the article provides valuable insights for developers working with Angular and the TestBed.