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

Readme

Keywords

none

Package Sidebar

Install

npm i rewire-loader

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • hallettj
  • originate-owner