# seneca-stub

> A utility for stubbing seneca.js patterns

Latest version **1.2.2** (published 2016-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install seneca-stub
pnpm add seneca-stub
yarn add seneca-stub
bun add seneca-stub
```

## 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 | 1.2.2 |
| Published | 2016-10-25 |
| First published | 2016-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.1.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Otavio Augusto Soares |
| Maintainers | otaviosoares |
| Keywords | seneca, test, stub, sinon |

## Links

- npm: https://www.npmjs.com/package/seneca-stub
- Repository: https://github.com/otaviosoares/seneca-stub
- Homepage: https://github.com/otaviosoares/seneca-stub#readme
- Issues: https://github.com/otaviosoares/seneca-stub/issues
- npm.io page: https://npm.io/package/seneca-stub

## Dependencies (2)

- [sinon](https://npm.io/package/sinon.md) ^1.17.4
- [lodash](https://npm.io/package/lodash.md) ^4.13.1

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2016-10-25
- 1.1.2 — 2016-06-13
- 1.0.2 — 2016-06-07
- 1.0.1 — 2016-06-07
- 1.0.0 — 2016-06-07

## README

# seneca-stub
A utility for stubbing seneca.js patterns using [Sinon.JS](https://github.com/sinonjs/sinon)

*This is based on Denis Luchkin-Zhou's stub utility from [seneca-as-promised](https://github.com/jluchiji/seneca-as-promised)*

# Install

```bash
npm install seneca-stub
```

# Getting Started

```js
const Seneca = require('seneca')();
require('seneca-stub')(Seneca);
```

### Return static data

```js
const stub = Seneca.stub('role:test,cmd:stub', { foo: 'bar' });
await Seneca.act('role:test,cmd:stub', { herp: 'derp' }); // { foo: 'bar' }

stub.data(); // { role: 'test', cmd: 'stub', herp: 'derp' }
```

### Use custom function

```js
const stub = Seneca.stub('role:test,cmd:stub', function(args, done) {
	var result = {greeting: 'hello '+ args.name }
	done(null, result)
});
await Seneca.act('role:test,cmd:stub', { name: 'john' }); // { greeting: 'hello john' }

stub.data(); // { role: 'test', cmd: 'stub', name: 'john' }
```

If value provided to `Seneca.stub` is an `Error`, then it will be thrown instead
of being returned.

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