Earlier quoted context omitted.
Agree. Especially in a language like Javascript. For testing - var myLib; if(process.env.NODE_ENV === "test") { myLib = require("../test/my_test_lib") } else { myLib = require("./my_lib") } or similar (you can obviously tighten this code up, too; I'm just being very explicit). Tada, you're injecting your test stubs in place of the real library when running in test. For the actual production use that a DI framework gi…
There's also stuff like rewire [0], which lets you change required values inside modules. Although every time I've tried it, I found it created more problems than it was solving. [0] https://www.npmjs.com/package/rewire
We use it to stub out imports in our unit tests and find it very easy.