DEV Community

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

Collapse
 
imthedeveloper profile image
ImTheDeveloper

Agree on the mocking. It feels dangerous to be faking npm modules to try and gain control of your test. Much simpler with injection and you aren't getting tied up in the mocking/unmocking workflows

Thread Thread
 
ld00d profile image
Brian Lampe

Isn't that the whole point though? You inject the npm modules with the sole purpose of mocking them. So in your unit test, you're not testing axios' connection to the web service, but via mocking, you can intercept those calls and stub a response for your unit test.