i-spy
A super simple spying library that mimics the jasmine spy API for use with other frameworks. Doesn't force you into the stub / mock / fake choice like sinon.js.
Installation (nodejs)
npm install i-spy
Api
createSpy()
Returns a function spy, optionally takes a function that will be executed when the spy is called.
var iSpy = require('i-spy');
var spy = iSpy.createSpy();
var spyWithAction(function () {
console.log('hi');
});
spy();
spyWithAction(); //-> hi
spy.calls
A 2 dimentional array of all the recorded calls to the spy.
var spy = iSpy; ;; spycalls00 // -> 'hello'spycalls01 // -> 'world'spycalls10 // -> '{foo: 'bar'}'
spy.wasCalled()
Returns a boolean that determines whether a spy has been called
var spy = iSpy; spy; // -> false ;spy; // -> true
spy.reset()
Clears any recorded calls on the spy
var spy = iSpy; ;spycallslength; // -> 1 spy; spycallslength; // -> 0
Usage
Simple usage:
var iSpy = ; var spy = iSpy; ;
Asynchronous tests:
var iSpy = ; ;
Spy behaviour can also be controlled via a fluent interface:
var iSpy = ; var erroringSpy = iSpy; var returningSpy = iSpy; var callThroughSpy = iSpy;