Jianwu Chen
1 min readJul 10, 2019

--

While I agree it’s better to depend on abstraction, regarding dependency injection, it will become an antipattern if we use it just for testing. DI used as testing tool is a common practice in static type languages such as Java and c#, as there’s no easy way to do mocking. However, in practice, over DI creates huge amount of accidentally complexities as overly exposed dependencies creates lots of burdens for component users. In your example, when the application grows, the sheer amount of wiring logic in the entry point (index.js) just becomes unmanageable.

Lucky in dynamics language world people solved testing issue more creatively and pragmatically without creating too much complexity, most frontend libraries give up DI concept, such as jest is a very good example to solve testing issues.

Hopefully this article won’t mislead less experienced frontend developers to choose a wrong tool.

--

--

Jianwu Chen
Jianwu Chen

Written by Jianwu Chen

Passionate Open Source Developer. ex-Ebayer, ex-Googler, ex-Linkin-er

No responses yet