Last active
May 28, 2016 14:05
-
-
Save supasympa/c0b6c63108e3d142909e99fb21811c96 to your computer and use it in GitHub Desktop.
Quick test spy function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;(function IIFE(global){ | |
| function noop(){} | |
| return function iSpyCreator(prevs, id){ | |
| prevs = prevs || {} | |
| id = id || Date.now().toString() | |
| prevs[id] = prevs[id] || {} | |
| return function iSpy(ject, fnName, fn){ | |
| fn = fn || noop; | |
| prevs[id][fnName] = ject[fnName] | |
| ject[fnName] = function(){ | |
| ject[fnName].callinfo.calls += 1 | |
| ject[fnName].callinfo.arguments.push[arguments] | |
| return fn() | |
| } | |
| ject[fnName].callinfo = {} | |
| ject[fnName].callinfo.calls = 0 | |
| ject[fnName].callinfo.arguments = [] | |
| ject[fnName].restore = function(){ | |
| ject[fnName] = prevs[id][fnName] | |
| } | |
| } | |
| } | |
| global.iSpy = iSpyCreator() | |
| global.iSpy.noop = noop | |
| }(this)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment