import { Spy } from "https://deno.land/x/rimbu@1.2.0/spy/index.ts";
const { fn } = Spy;
Returns a spied function instance that tracks the function calls and optionally uses some original or stub implementation.
Examples
Example 1
Example 1
function f(x: number, y: number) {
return x + y;
}
const spy = Spy.fn(f, (x) => -x);
spy(4, 5);
// => -4
spy.nrCalls;
// => 1
spy.calls;
// => [[4, 5]]
Type Parameters
F extends Func
Parameters
optional
originalFn: F- (optional) the original function to spy on, if stubbed still useful to supply to get the correct types
optional
originalStub: Spy.FnStub<F>- (optional) the default stub implementation to use when the function is called
optional
onCall: (args: Parameters<F>) => void- (optional) a callback function that receives the parameters used on each function call