Skip to content

Instantly share code, notes, and snippets.

@SherryH
Created December 31, 2016 04:24
Show Gist options
  • Save SherryH/c38ac9ffcfabc008f6436f4c7798a920 to your computer and use it in GitHub Desktop.
Save SherryH/c38ac9ffcfabc008f6436f4c7798a920 to your computer and use it in GitHub Desktop.
Make a Spy
// a highly simplified version of a spy which counts total call
var spy = function(object, property){
var origFn = object[property];
var spyFn = function(){
spyFn.callCount++;
return origin.apply(object, arguments);
}
spyFn.callCount = 0;
object[property] = spyFn;
return spyFn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment