# cf-test-stub

> Cloudflare Stub Test Util

Latest version **2.2.5** (published 2018-03-28) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install cf-test-stub
pnpm add cf-test-stub
yarn add cf-test-stub
bun add cf-test-stub
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.2.5 |
| Published | 2018-03-28 |
| First published | 2016-05-16 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James Kyle |
| Maintainers | adamschwartz, cf-ci, cf-ci-write, ereeves, hamidagh, handrews, hturan, inikulin, jculvey, johndotawesome, jparyani-cloudflare, manatarms, marksteyn, miksu, mpint, nkcmr, rreverser, ryan0x44, sejoker, teffenellis, terinjokes, toekneestuck, vasturiano |

## Links

- npm: https://www.npmjs.com/package/cf-test-stub
- npm.io page: https://npm.io/package/cf-test-stub

## Recent versions

- 2.2.5 (latest) — 2018-03-28
- 2.2.4 — 2018-03-27
- 2.2.3 — 2017-10-23
- 2.2.2 — 2017-10-20
- 2.2.1 — 2017-09-22
- 2.2.0 — 2017-03-20
- 2.1.0 — 2017-03-20
- 2.0.0 — 2016-12-01
- 1.0.1 — 2016-06-14
- 1.0.0 — 2016-05-16

## README

# cf-test-stub

> Cloudflare Stub Test Util

This module allows you to create stubs that get automatically restored between
tests in Mocha.

## Installation

```sh
$ npm install --save-dev cf-test-stub
```

> Note: This module needs to be run within the context of Mocha

## Usage

```js
import assert from 'assert';
import {createStub, stubMethod} from 'cf-test-stub';

describe('exampleModule', () => {
  it('should do something', () => {
    const callback = createStub();
    exampleModule.doSomething(callback);
    assert.ok(callback.called);
    assert.equal(callback.callCount, 1);
  });

  it('should do something else', function() {
    const methodToStub = stubMethod(exampleModule, 'methodToStub', arg => {
      assert.equal(arg, 'value');
    });

    exampleModule.doSomethingElse();

    assert.ok(methodToStub.called);
    assert.equal(methodToStub.callCount, 1);

    // We can restore the original method ourselves, but cf-test-stub will
    // restore it automatically after the test.
    methodToStub.restore();
  });
});
```

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