New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

require-mocked

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-mocked

Utility library that allows you to inject your mocks into modules code

latest
Source
npmnpm
Version
0.2.2
Version published
Maintainers
1
Created
Source

require-mocked

Node.js library that allows you to inject your mocks into your modules code.

Installation

npm install require-mocked

Usage

Suppose you want to test some module that uses fs (eiser directly, or throught one of its dependencies) but you want it to use some stun instead of the real FS.

var requireMocked = require('require-mocked');

var moduleUnderTest = requireMocked(require.resolve('./path/to/your/module'), {
    mocks: {
        fs: {
            //your stub code
        }
    }
});

Module exposes single function - requireMocked. It accepts following parameters:

  • path - absolute path to the module you want to load. Use require.resolve to get it from relative path;
  • opts - loading options:
    • opts.mocks - mocks to use when loading module or its dependencies. Keys of the object represents module ids, values - the object to use instead of real module.
    • opts.resolves - stub require.resolve for the loaded module so it will return given path for instead of original. Format is {"moduleId": "stub/path"}.
    • opts.ignoreMocks - array of the module id that will always load real modules instead of mocks.

Similar projects

  • SandboxedModule - doesn't support recursive mocking, but may be more functional in other areas.

License

Licensed under MIT license.

Keywords

mock

FAQs

Package last updated on 12 Sep 2013

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