Angular · Junior · Question 33 of 75
Why is dependency injection useful for testing?
- ✓Correct answer: Tests can provide a fake implementation of a service without changing the component
- 2DI makes the code run faster in tests
- 3It disables change detection in tests
Explanation
TestBed.configureTestingModule({ providers: [{ provide: ApiService, useValue: fakeApi }] }) swaps the real service for a stub. Components only depend on what they inject.