npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

This package has been deprecated

Author message:

WARNING: This project has been renamed to babel-plugin-rewire. Install using babel-plugin-rewire Instead.

babel-rewire-plugin

0.1.0 • Public • Published

babel-rewire-plugin

A Babel plugin that adds the ability to rewire modul dependency.

Build Status

It is inspired by rewire.js and transfers its concepts to es6 using babel.

It is for writing tests, specifically to mock the dependencies of the module under test.

Therfore for each module it adds and exports the methods GetDependency, Rewire, and ResetDependency. These methods allow to rewire the module under test. Furthermore in case of a default Export these methods are assigned to the existing default export.

e.g.

Module to test (React Component)

import ChildComponent from 'child-component-module';
 
export default class MyFancyWrapperComponent extends React.Component {
 
    render() {
        return (<div className="wrapper-style">
            <ChildComponent {...this.props} />
        </div>);
    }
}

TestCode

import ComponentToTest from MyFancyWrapperComponent;
 
ComponentToTest.__Rewire__('ChildComponent', React.createClass({
    render: function() { return <div {...this.props}></div>; }
}));
....
 
ComponentToTest.__ResetDependency__('ChildComponent');

Install

$ npm install babel babel-rewire-plugin

Use

$ babel --plugins babel-rewire-plugin

or:

require("babel").transform("code", { plugins: ["object-assign"] });

with webpack use the following loader:

{test: /src\/js\/.+\.js$/, loader: 'babel-loader?plugins=babel-rewire-plugin' }

Release History

  • 0.1.0 Initial release

License

The ISC License (ISC)

Copyright (c) 2015, Robert Binna r.binna@synedra.com

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

install

npm i babel-rewire-plugin

Downloadsweekly downloads

3

version

0.1.0

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability