NestJS · Junior · Question 25 of 75
What is the main benefit of dependency injection?
- 1It removes the need for modules
- 2It makes TypeScript compile faster
- ✓Correct answer: Classes don't create their dependencies themselves, so they're easier to replace (e.g. with mocks in tests) and to configure
Explanation
In tests you can override a provider with a fake implementation without changing the class under test.