re: Why do I have to use Dependency Injection in JS? VIEW POST

VIEW PARENT COMMENT VIEW FULL DISCUSSION
 

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

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.

code of conduct - report abuse