rewire-loader

1.1.0 • Public • Published

rewire-loader CircleCI

Adds rewire-like bindings to a webpack loader. Works well with mocha-webpack

Usage

Suppose you have a module.js file with the content:

const SOME_CONSTANT = 15;
var someDependency = require('some-dependency');
 
module.exports = function() {
  return someDependency();
};

You can stub out your dependencies with __set__

myModule = require('rewire!./module.js');
myModule.__set__('someDependency', mockDependency);
myModule(); // returns mockDependency

You can also get values with __get__

myModule = require('rewire!./module.js');
myModule.__get__('SOME_CONSTANT'); // returns 15

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.00
1.0.30
1.0.20
1.0.11
1.0.00

Package Sidebar

Install

npm i rewire-loader

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • hallettj
  • originate-owner