forget

v1.0.0
Mocking for commonjs dependencies
mock commonjs require dependencies

forget

Simple dependency mocking for commonjs. Works in most cases for Node, browserify, and webpack.

Installation

npm install forget

Usage

Suppose you have a module that uses jquery.ajax and want to mock out that functionality:

//module.js
var $ = require('jquery')
$.ajax({
//...
})

Then in your unit tests:

//moduleSpec.js
var forget = require('forget')
var fakeJQuery = { ajax: function (options) { return options } }
forget(require('jquery'), fakeJQuery)
var module = require('./module.js')

/* Do some testing here */

forget.restore()

Now in your test, you'll use the mocked out version of jquery instead of the real thing.

Author

Thom Blake

License

ISC

Metadata

  • ISC
  • Whatever
  • Thom Blake
  • released 10/22/2015

Downloads

Maintainers