Last active
May 1, 2020 11:32
-
-
Save PCouaillier/87a65dc803053e5ab466f8728ecef051 to your computer and use it in GitHub Desktop.
spy.ts
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
import {inspect} from 'util'; | |
/** | |
* This show arguments and output of a function / a method | |
* | |
* @param {Function} thisArg | |
* @param {Function} func | |
*/ | |
export const spy = <T, A extends any[], R, F extends (this: T, ...args: A) => R>(thisArg: T, func: F): F => { | |
return function() { | |
console.debug(inspect(arguments)); | |
const res = func.apply(thisArg, arguments as any); | |
console.debug(inspect(res)); | |
return res; | |
} as F; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment