# stubs

> Easy method stubber.

Latest version **3.0.0** (published 2017-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install stubs
pnpm add stubs
yarn add stubs
bun add stubs
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2017-01-13 |
| First published | 2014-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Stephen Sawchuk |
| Maintainers | stephenplusplus |
| Keywords | stubs |

## Links

- npm: https://www.npmjs.com/package/stubs
- Repository: https://github.com/stephenplusplus/stubs
- Issues: https://github.com/stephenplusplus/stubs/issues
- npm.io page: https://npm.io/package/stubs

## 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
- [@ghostry/fabricator-extension-faker-v10](https://npm.io/package/@ghostry/fabricator-extension-faker-v10.md) — 0 weekly downloads
- [@depup/casual](https://npm.io/package/@depup/casual.md) — 0 weekly downloads
- [@availity/mock-server](https://npm.io/package/@availity/mock-server.md) — 0 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2017-01-13
- 2.0.0 — 2015-07-07
- 1.1.2 — 2014-10-17
- 1.1.1 — 2014-10-17
- 1.1.0 — 2014-10-16
- 1.0.0 — 2014-10-16

## README

# stubs

> It's a simple stubber.

## About

For when you don't want to write the same thing over and over to cache a method and call an override, then revert it, and blah blah.


## Use
```sh
$ npm install --save-dev stubs
```
```js
var mylib = require('./lib/index.js')
var stubs = require('stubs')

// make it a noop
stubs(mylib, 'create')

// stub it out
stubs(mylib, 'create', function() {
  // calls this instead
})

// stub it out, but call the original first
stubs(mylib, 'create', { callthrough: true }, function() {
  // call original method, then call this
})

// use the stub for a while, then revert
stubs(mylib, 'create', { calls: 3 }, function() {
  // call this 3 times, then use the original method
})
```


## API

### stubs(object, method[[, opts], stub])

#### object
- Type: Object

#### method
- Type: String

Name of the method to stub.

#### opts
- (optional)
- Type: Object

##### opts.callthrough
- (optional)
- Type: Boolean
- Default: `false`

Call the original method as well as the stub (if a stub is provided).

##### opts.calls
- (optional)
- Type: Number
- Default: `0` (never revert)

Number of calls to allow the stub to receive until reverting to the original.

#### stub
- (optional)
- Type: Function
- Default: `function() {}`

This method is called in place of the original method. If `opts.callthrough` is `true`, this method is called *after* the original method is called as well.

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