m-stub

1.0.1 • Public • Published

Stub

Installation

npm install stub [--save-dev]

Usage

Require the module:

var stub = require('stub');

The stub object now has two public methods available:

stub.inject(modulePath, ...dependencyPaths)

Requires a module and stubs its dependencies.

Example:

foo.js:

var bar = require('bar');

module.exports = {
    foo: function () {
        return 'foo' + bar.print();
    }
}

bar.js:

module.exports = {
    print: function () {
        return 'bar';
    }
};

foo.test.js:

var stub = require('stub');
var fooWithStubbedBar = stub.inject('./foo', './bar');

/* Use fooWithStubbedBar for testing... */

stub.get(module, dependency [, method])

Returns the stub of a module dependency. Optionally, you can provide the stubbed method name as an argument to get access to the stubbed method directly.

Example (with the same modules as the example above):

foo.test.js:

var stub = require('stub');
var fooWithStubbedBar = stub.inject('./foo', './bar');

/* Get entire stub: */
var stubbedBar = stub.get(fooWithStubbedBar, './bar');

/* Or get stubbed method: */
var stubbedBarPrintMethod = stub.get(fooWithStubbedBar, './bar', 'print');

Readme

Keywords

none

Package Sidebar

Install

npm i m-stub

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • k001atv