# @segment/spy

> Test spy

Latest version **1.1.0** (published 2016-12-08) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @segment/spy
pnpm add @segment/spy
yarn add @segment/spy
bun add @segment/spy
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-12-08 |
| First published | 2016-05-18 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Segment |
| Maintainers | anthonyshort, benjamin88, calvinfo, chrisbuttery, dominicbarnes, hanothan, lambtron, ndhoule, notjrbauer, reinpk, rowno, segment-admin, segmentio, stephenmathieson, stevenmiller888, tejasmanohar, thehydroimpulse, therebelrobot, timhudson, tonyxiao, yields |
| Keywords | spy, test |

## Links

- npm: https://www.npmjs.com/package/@segment/spy
- Repository: https://github.com/segmentio/spy
- Homepage: https://github.com/segmentio/spy#readme
- Issues: https://github.com/segmentio/spy/issues
- npm.io page: https://npm.io/package/@segment/spy

## Dependencies (3)

- [@ndhoule/clone](https://npm.io/package/@ndhoule/clone.md) ^1.0.0
- [@ndhoule/extend](https://npm.io/package/@ndhoule/extend.md) ^2.0.0
- [@segment/equals](https://npm.io/package/@segment/equals.md) ^1.1.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
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2016-12-08
- 1.0.1 — 2016-06-02
- 1.0.0 — 2016-05-18

## README

# spy

Test spy.

[![CircleCI](https://circleci.com/gh/segmentio/spy.svg?style=shield&circle-token=bde46008aa250c15e0011ae95b65485deb472c83)](https://circleci.com/gh/segmentio/spy)
[![Codecov](https://img.shields.io/codecov/c/github/segmentio/spy/master.svg?maxAge=2592000)](https://codecov.io/gh/segmentio/spy)

## Installation

```sh
$ npm install @segment/spy
```

## API

### spy(obj, method)

  Create a spy with optional `obj`, `method`.

  Examples:

```js
  var s = spy();
  var s = spy(console, 'log');
  var s = spy(spy);
```

#### args[]

An array that holds all arguments.

Examples:

```js
spy(1, 2, 3);
spy(4, 5, 6);

spy.args[0]; // => [1, 2, 3]
spy.args[1]; // => [4, 5, 6]
```

#### returns[]

An array that holds all returned values.

Examples:

```js
spy = require('spy')(window.btoa);
spy('test');
spy('foo');

s.returns[0]; // => "dGVzdA=="
s.returns[1]; // => "Zm9v"
```

#### .once(), .calledOnce

`true` if the spy was called only once.

Examples:

```js
spy();
spy.once(); // => true
spy.calledOnce; // => true

spy();
spy.once(); // => false
spy.calledOnce; // => false
```

#### .twice(), .calledTwice

`true` if called twice.

#### .thrice(), .calledThrice

`true` if called thrice.

#### .got(...), .calledWith(...)

`true` if the spy was called with `...`

Examples:

```js
spy(1, 2, 3);
spy.got(1, 2, 3); // => true

spy(4, 5, 6);
spy.got(1, 2, 3); // => false

spy(1, 2, 3);
spy.got(1, 2) // => true

spy(1, 2, 3);
spy.got(1) // => true
```

#### .gotExactly(...), .calledWithExactly(...)

`true` if the spay was called with exactly `...`

Examples:

```js
spy(1, 2, 3);
spy.got(1, 2, 3); // => true

spy(4, 5, 6);
spy.got(1, 2, 3); // => false

spy(1, 2, 3);
spy.got(1, 2) // => false

spy(1, 2, 3);
spy.got(1) // => false
```

#### .returned(...)

`true` if the spy was called with `...`

Examples:

```js
spy = spy(window.btoa);

spy('test');
spy.returned('dGVzdA=='); // => true
```

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