Skip to content

ichernev/injectr

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

injectr

Finally, a solution to node.js dependency injection

Install it

npm install injectr. Boom.

Use it

var injectr = require('injectr');
var myScript = injectr('./lib/myScript.js', {
    fs : mockFs,
    crypto : mockCrypto
});

Now when you require('fs') or require('crypto') in myScript.js, what you get is mockFs or mockCrypto. It works with relative requires too. Just make sure you make the property name exactly the same as what is required in the file being tested.

Treat injectr like require for your tests, with a second argument to pass in your mocks. The only thing to note is that paths are relative to the working directory, not to the file location as with require.

Share it

injectr is under the MIT License. Fork it. Modify it. Pass it around.

About

Finally, a solution to node.js dependency injection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 99.0%
  • CoffeeScript 1.0%