fn-spy
creating spies for your functions
api
const spy = require('fn-spy')
spy(function[, thisArg])
function the function to be spied thisArg the this argument for the call (to be used with Classes or Objects)
methods
spy.calledCount() integer, returns the number of times a function as called
spy.calledWith() array, returns the arguments passed to the function
spy.getReturns() array, returns the output of the executed functions
spy.restore() function, restores the function to the initial state
spy an emitter function
const spyMyEmitter = spy.emitter()
and will return the same methods as above
spy a callback function
const spyMyEmitter = spy.callback()
and will return the same methods as above
examples
generic example
const spy = { return argslength} let spiedFn = // calledCountspiedFn// will return 2 // calledWithspiedFn// will return [[1, 2, 3]] // restorespiedFn = spiedFn// now spiedFn is retored to the initial state
emitter example
const EE = const spy = const myEmitter = const spyEmitter = spy myEmitter myEmitter spyEmitter// will return 1spyEmitter// will return [[]]
callback example
const spy = const spyCallback = spy { } spyCallback// will return 1spyCallback// will return [[]]
Class / Object example
{ thissn = '9-9-0-6-9-4-7-X-B-7-1'} BladeRunnerprototype { return thissn} const deckard = const spy = // returns '9-9-0-6-9-4-7-X-B-7-1' spy// will return 1spy// will return [[]]spy// will return ['9-9-0-6-9-4-7-X-B-7-1']