Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/spy/index.ts>Spy.fn

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Spy.fn
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

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]]

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