One use case is that sometimes it doesn't make sense to mock out functions in unit tests... instead it makes more sense to mock out objects where ever they are imported. (Yes, it sometimes makes sense to use BDD and this avoids the issue)
Another use case is when setting up a module is expensive or complex, and it makes sense to have the setup code in one place.
What's the recommended strategy for nodejs? I've looked at some dependency injection and service locator packages but they don't seem to be that popular.
Addendum: Are there any open source applications that exemplify good practices in this space?
Addendum2: We use ES6 (and therefore, the const
keyword) and so rewire
doesn't work.