1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1× 1× 252× 9166× 4587× 252× 252× 252× | import { SpyCall, RestorableSpy } from "../_spying"; export function SpyOn(target: any, functionName: string): RestorableSpy { let spy = new RestorableSpy(target, functionName); target[functionName] = (...args: Array<any>) => { return spy.call(args); }; // expose spy's calls on function target[functionName].calls = spy.calls; // expose spy's restore function target[functionName].restore = spy.restore.bind(spy); return spy; } |