# require-mocked

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

Latest version **0.2.2** (published 2013-09-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install require-mocked
pnpm add require-mocked
yarn add require-mocked
bun add require-mocked
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2013-09-12 |
| First published | 2013-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Sergej Tatarincev |
| Maintainers | sevinf |
| Keywords | mock, stub, fake, modules, testing |

## Links

- npm: https://www.npmjs.com/package/require-mocked
- Repository: https://github.com/SevInf/require-mocked
- Issues: https://github.com/SevInf/require-mocked/issues
- npm.io page: https://npm.io/package/require-mocked

## Dependencies (1)

- [require-like](https://npm.io/package/require-like.md) ~0.1.2

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [n8n-nodes-ecom-adspy-tco](https://npm.io/package/n8n-nodes-ecom-adspy-tco.md) — 0 weekly downloads
- [mokapi-storybook-addon](https://npm.io/package/mokapi-storybook-addon.md) — 0 weekly downloads
- [mokapi-msw-adapter](https://npm.io/package/mokapi-msw-adapter.md) — 0 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2013-09-12
- 0.2.1 — 2013-09-02
- 0.2.0 — 2013-08-08
- 0.1.1 — 2013-08-01
- 0.1.0 — 2013-07-31

## README

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.

```javascript
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](https://github.com/felixge/node-sandboxed-module) - doesn't support recursive mocking, but
may be more functional in other areas.

## License

Licensed under MIT license.

---
_Source: https://npm.io/package/require-mocked · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
