Load a module with it's require's mocked out
JavaScript
Switch branches/tags
Nothing to show
Latest commit 8da6f76 Jan 29, 2013 @Raynos Raynos 0.1.1
Permalink
Failed to load latest commit information.
examples initial Jan 23, 2013
test initial Jan 23, 2013
.gitignore no u node_modules Jan 23, 2013
.npmignore initial Jan 23, 2013
.testem.json initial Jan 23, 2013
.travis.yml initial Jan 23, 2013
LICENCE initial Jan 23, 2013
README.md not private Jan 23, 2013
index.js initial Jan 23, 2013
package.json 0.1.1 Jan 29, 2013

README.md

mock

build status

browser support

Load a module with it's require's mocked out

Works in both node and browserify

Example

var realB = require("./fixtures/b")

var b = mock("./fixtures/b", {
    fs: {
        readFileSync: function (uri) {
            if (uri === "clowns.txt") {
                return "some clowns"
            }
        }
    }
    , "./fixtures/c": null
    , "./fixtures/a": function () {
        return 42
    }
}, require)

// use b. It's reference to fs and fixtures/a have been replaced with
// your passed objects

Limitations:

  • You have to require the thing your mocking out or browserify won't load it and all it's dependencies into the bundle.
  • When you set a dependency to null your saying don't overload that dependency with this value, but do nuke it from the cache. This is useful when you want to mock out something ./fixtures/c depends on but not touch the implementation of ./fixtures/c

Installation

npm install mock

Contributors

  • Raynos

MIT Licenced