SimpleSpy.js
Standalone library for creating spies in Node.js. Easy to use. No dependancies.
npm install simplespy
Usage
SimpleSpy exports a simple spyOn
function that accepts a single function as a parameter and returns a spy. SimpleSpy does not modify the given function.
spyOn
Accepts a function. Returns a spy.
var spyOn = ;{return num + 5;}var spy = ; // create spy
callCount
Doesn't accept arguments. Returns the number of times the spy has been called.
var spyOn = ;{return num + 5;}var spy = ; // create spy; // returns 7// returns 8spy; // returns 2
wasCalled
Doesn't accept arguments. Returns a boolean indicating if the spy has been called.
var spyOn = ;{return num + 5;}var spy = ; // create spy; // returns 7// returns 8spy; // returns 2spy; // returns true
wasCalledWith
Accepts a single argument. Returns a boolean indicating if the spy has been called with the given argument.
var spyOn = ;{return num + 5;}var spy = ; // create spy; // returns 7// returns 8spy; // returns 2spy; // returns truespy; // returns true
returned
Accepts a single argument. Returns a boolean indicating if the spy has been called with the given argument.
var spyOn = ;{return num + 5;}var spy = ; // create spy; // returns 7// returns 8spy; // returns 2spy; // returns truespy; // returns truespy; // returns true
Running tests
npm test
License
MIT. Copyright (c) Sterling Whitley