Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you're doing node-style (cjs) modules, you can use something like proxyquire[1] with testing to inject dependencies without complicating your modules, or creating logical indirection. If the only reason you have DI is for testing in a scripted platform, you're probably doing something wrong.

You can write, compose and composite plain objects and pure functions in JS modules that can be tested very easily without resorting to complex DI systems (with naming disconnects even).

[1] https://www.npmjs.com/package/proxyquire



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: