Note
Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.
Test spy.
$ npm install @segment/spyCreate a spy with optional obj, method.
Examples:
var s = spy();
var s = spy(console, 'log');
var s = spy(spy);An array that holds all arguments.
Examples:
spy(1, 2, 3);
spy(4, 5, 6);
spy.args[0]; // => [1, 2, 3]
spy.args[1]; // => [4, 5, 6]An array that holds all returned values.
Examples:
spy = require('spy')(window.btoa);
spy('test');
spy('foo');
s.returns[0]; // => "dGVzdA=="
s.returns[1]; // => "Zm9v"true if the spy was called only once.
Examples:
spy();
spy.once(); // => true
spy.calledOnce; // => true
spy();
spy.once(); // => false
spy.calledOnce; // => falsetrue if called twice.
true if called thrice.
true if the spy was called with ...
Examples:
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) // => truetrue if the spay was called with exactly ...
Examples:
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) // => falsetrue if the spy was called with ...
Examples:
spy = spy(window.btoa);
spy('test');
spy.returned('dGVzdA=='); // => true