GithubHelp home page GithubHelp logo

thesavior / rewireify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from i-like-robots/rewireify

0.0 2.0 0.0 31 KB

Rewireify is a port of Rewire for Browserify that adds setter and getter methods to each module so that their behaviour can be modified for better unit testing.

License: Other

JavaScript 100.00%

rewireify's Introduction

Rewireify Build status

Rewireify is a port of Rewire for Browserify that adds setter and getter methods to each module so that their behaviour can be modified for better unit testing. With Rewireify you can:

  • Inject mocks for other modules
  • Leak private variables
  • Override variables within the module

Rewireify is compatible with Browserify 3+

Usage

First install and save Rewireify into your project's development dependencies:

$ npm install rewireify --save-dev

Include the Rewireify transform as part of your test bundle:

$ browserify -e app.js -o test-bundle.js -t rewireify -s test-bundle

Rewireify can also ignore certain files with the --ignore option and a filename or glob expression. Multiple files or patterns can be excluded by separating them with commas:

$ browserify -e app.js -o test-bundle.js -t [ rewireify --ignore filename.js,**/*-mixin.js ] -s test-bundle

Now you can inspect, modify and override your modules internals in your tests. The __get__ and __set__ methods are the same as Rewire:

var bundle = require("./path/to/test-bundle");

// Private variables can be leaked...
subject.__get__("secretKey");

// ...or modified
subject.__set__("secretKey", 1234);

// Nested properties can be inspected or modified
subject.__set__("user.firstname", "Joe");

// Dependencies can be mocked...
subject.__set__("config", {
  cache: false,
  https: false
});

// ...or methods stubbed
subject.__set__("http.get", function(url, cb) {
  cb("This method has been stubbed");
});

// And everything can be reverted
var revert = subject.__set__("port", 3000);

revert();

For more details check out the Rewire documentation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.