Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

stub-require

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stub-require

Automatically stub modules via proxyquire

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

stubrequire

Automatically create stubbed-out versions of node.js modules, ala Jest's autoMock.

Usage:

// BigComplexModule.js
module.exports = {
  foo: function() { return 42; }
};

// foo.js
module.exports = function() {
  return require('./BigComplexModule').foo();
};

// foo-test.js
var stubRequire = require('stubrequire')(['BigComplexModule']),
    foo = stubRequire('./foo');

foo();  // returns undefined, not 42.

stubrequire will mock out both methods and classes, i.e. if a module exports module.foo, then new module.foo() will return an object with the same methods as the original, but all stubbed out.

Installation

npm install --save-dev stubrequire

FAQs

Package last updated on 28 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts