This package has been deprecated

Author message:

This package has been deprecated. Please find this package under its new name @cloudflare/test-stub.

cf-test-stub

2.2.5 • Public • Published

cf-test-stub

Cloudflare Stub Test Util

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

Installation

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

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

Usage

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();
  });
});

Readme

Keywords

none

Package Sidebar

Install

npm i cf-test-stub

Weekly Downloads

7

Version

2.2.5

License

BSD-3-Clause

Unpacked Size

6.79 kB

Total Files

8

Last publish

Collaborators

  • lbarthonet
  • cf-media-manager
  • jacobbednarz
  • celso
  • cf-radar
  • dash_service_account
  • g4brym
  • snigdha34
  • wrangler-publisher
  • marksteyn
  • chiminator
  • sgoodhew_cf
  • terinjokes
  • third774
  • jsteinberger
  • jasnell
  • asapzacy
  • pcostanzo
  • gregbrimble
  • geelen
  • rexscaria
  • dcruz_cf
  • xuranwang
  • jculvey
  • sejoker
  • vasturiano
  • cf-ci-write
  • segments-write
  • thibmeu
  • xortive
  • gurjinder
  • cf-ci2
  • lvalenta
  • worenga