spyny
A tiny spy library for Node.js.
spy([callback])
Use the spy
function to create a new spy.
var spy = ;var mySpy = ;
You can also provide a callback to be ran when the spy is called. It will recieve all arguments that are passed to the spy.
var mySpy = ; console;// Hello, Dave!
called
Check if a spy was called.
;console;// true
callCount
Check how many times a spy was called.
;;console;// 2
callWith()
Alternative way of setting the spy callback.
mySpy; console;// Yo, Dave!
getCall()
Get the details of a specific call.
;console;// {// args: ['yo!']// }
reset()
Flush all previous call data.
;mySpy;console;// false
returns()
Assign a return value for the spy.
mySpy;console;// Howdy!
===
spy.on(obj, method, [callback])
Spy on an objects method. Contains all properties and methods of spy()
.
var Dave = { return 'Hello, ' + person + '!'; }; spy;console;// Howdy
You can also pass in a callback to be invoked.
spy; console;// Howdy, Gabe.
restore()
Restore a method to its previous state.
spy;Davegreet;console;// Hello, Gabe!
passthrough()
When called it instructs the spy to use the original method as the callback.
spy;console;// Hello, Gabe!console;// {// args: ['Gabe']// }
===
spy.sandbox()
Create a sandbox object to contain all of your spies. Useful for mass cleanups.
var sandbox = ;var spy = sandboxspy;
spy([callback])
Creates a spy contained within the sandbox. Contains the same properties and methods as a normal spy
.
var sandbox = ;var spy = sandboxspy;var mySpy = ; ;console;// true
spy.on(obj, method, [callback])
Creates a spy for an object's method within the sandbox. Contains the same properties and methods as a normal spy.on()
var sandbox = ;var spy = sandboxspy; spy;console;// false
reset()
Resets all spies within the sandbox.
var sandbox = ;var spy = sandboxspy;var spy1 = ;var spy2 = ; ;;; sandbox; console;// falseconsole;// 0
restore()
Restores all spies created via spy.on()
to previous state.
var sandbox = ;var spy = sandboxspy; spy; sandbox;console;// Hello, Gabe!
flush()
Clear all cached spies from the sandbox. Note: this does not restore/reset spies, this simply clears them all from the sandbox cache.
var sandbox = ;var spy = sandboxspy; spy; sandbox;sandbox; // `Dave.greet` is still a spy
License
ISC