Skip to content

Instantly share code, notes, and snippets.

@PCouaillier
Last active May 1, 2020 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PCouaillier/87a65dc803053e5ab466f8728ecef051 to your computer and use it in GitHub Desktop.
Save PCouaillier/87a65dc803053e5ab466f8728ecef051 to your computer and use it in GitHub Desktop.
spy.ts
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