1

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.

morgs32
  • 1,439
  • 3
  • 17
  • 26
  • I'd say DI is definitely the Node Way of doing things. Packages like Express are great because they were built leveraging DI/middleware. I'd look at this [answer](http://stackoverflow.com/questions/9250851/do-i-need-dependency-injection-in-nodejs-or-how-to-deal-with), it covers a good deal of what you're asking. – peteb May 25 '16 at 22:12

0 Answers0