Mocking ES6 module dependencies with proxyquire
In part one, I wrote about mocking ES6 module dependencies using the ES6 native import * from
construct. It works mostly fine. However, you need to be aware of a potential issue:
- You need to import modules to mock them, which means that those modules will be evaluated. That may be a problem if you don’t want the code in this modules to be executed.
Another method I found to work well is using proxyquire. It is one of many libraries aiming to streamline mocking dependencies to simplify unit testing.
Read more →