Using Dependency Injection in Your JavaScript Unit Tests with Rewire

added by JavaScript Kicks
3/21/2015 2:55:50 PM

290 Views

You probably already know that to do JavaScript testing well, you need to make sure you are testing the following: Injecting mocks for other modules Leaking private variables Overriding variables within the module rewire is a tool for helping test for the above. It provides an easy way to perform dependency injection, plus adds a special setter and getter to modules so you can modify their behaviour. What rewire doesn’t do is load the file and evaluate the contents to emulate the require mechanism. It actually uses Node’s own require to load the module.


0 comments