Skip to content

Commit

Permalink
Reflect API change
Browse files Browse the repository at this point in the history
Oops. Missed this update from the 0.5.0 release, but it can wait until the
next release to be updated.
  • Loading branch information
nathanmacinnes committed Apr 11, 2014
1 parent f94171d commit b21f8fb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -9,7 +9,7 @@ _Finally, a solution to node.js dependency injection_
## Use it ##

var injectr = require('injectr');
var myScript = injectr('./lib/myScript.js', {
var myScript = injectr('../lib/myScript.js', {
fs : mockFs,
crypto : mockCrypto
});
Expand All @@ -29,7 +29,7 @@ your tests if you are upgrading from v0.4 or below.
an optional third argument. Provide an object, and **injectr** will modify it
as necessary and use that as the context.

var myScript = injectr('./lib/myScript.js', {}, {
var myScript = injectr('../lib/myScript.js', {}, {
Date : mockDate,
setTimeout : mockSetTimeout
});
Expand Down
51 changes: 51 additions & 0 deletions README.md~
@@ -0,0 +1,51 @@
# 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`.

Treat **injectr** like `require` for your tests, with a second argument to pass
in your mocks.

**Paths are now relative to the current file, just like require.** Please update
your tests if you are upgrading from v0.4 or below.

### Context ###

**injectr** gives you access to the context of the **injectr**'d file via
an optional third argument. Provide an object, and **injectr** will modify it
as necessary and use that as the context.

var myScript = injectr('./lib/myScript.js', {}, {
Date : mockDate,
setTimeout : mockSetTimeout
});

As of version 0.4, **injectr** doesn't create a full node.js context for you to
use. Instead, it isolates your script in its own sandbox, allowing you to
include mocks of only the bits that your script needs.

### CoffeeScript ###

**injectr** compiles any *.coffee files for you, so you can test your
CoffeeScript too. The default settings can be changed by overwriting the
`injectr.onload` function. It takes the filename and file contents as
arguments, and returns the compiled script.

## Share it ##

**injectr** is under the [MIT License](http://www.opensource.org/licenses/MIT).
[Fork it](https://github.com/nathanmacinnes/injectr). Modify it. Pass it around.

0 comments on commit b21f8fb

Please sign in to comment.