1.0.31 • Published 3 years ago
@cloudflare/test-stub v1.0.31
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();
});
});
1.0.31
3 years ago
1.0.29
3 years ago
1.0.30
3 years ago
1.0.28
3 years ago
1.0.27
3 years ago
1.0.26
3 years ago
1.0.25
3 years ago
1.0.24
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.18
4 years ago
1.0.17
4 years ago
1.0.20
4 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago