DEV Community

Discussion on: Why do I have to use Dependency Injection in JS?

Collapse
 
sebbdk profile image
Sebastian Vargr • Edited

If the dependencies are updated and the API changed, then our test will not' fail because the mocks did not get updated.

Which is why integration tests should always be done with real dependencies.

On top of that dependency injection is a anti-pattern on the level of inflection and convention over configuration.

It's hard to debug, hard to test, and hard to maintain or requires a lot of domain knowledge.

We have functional programming patterns today, which can serve the same purposes but without the drawbacks listed above.


TL;DR
Use arguments, not dependency injection.

Dependency injection is how you get AngularJS (and Angular for mysterious reasons).

Edit, Mis-worded a sentence.