Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created November 16, 2016 13:41
Show Gist options
  • Save coderofsalvation/5c458825570538525dba4e3969f47daa to your computer and use it in GitHub Desktop.
Save coderofsalvation/5c458825570538525dba4e3969f47daa to your computer and use it in GitHub Desktop.

Revisions

  1. coderofsalvation created this gist Nov 16, 2016.
    16 changes: 16 additions & 0 deletions spy.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    function spy (fn) {
    if (!fn) fn = function() {};

    function proxy() {
    var args = Array.prototype.slice.call(arguments);
    proxy.calls.push(args);
    proxy.called = true;
    fn.apply(this, args);
    }

    proxy.prototype = fn.prototype;
    proxy.calls = [];
    proxy.called = false;

    return proxy;
    }