Function assertSpyCallArg

  • Asserts that a spy is called with a specific arg as expected.

    Type Parameters

    • Self

      The self type of the spy function.

    • Args extends unknown[]

      The arguments type of the spy function.

    • Return

      The return type of the spy function.

    • ExpectedArg

      The expected type of the argument for the spy to be called.

    Parameters

    • spy: SpyLike<Self, Args, Return>

      The spy to check.

    • callIndex: number

      The index of the call to check.

    • argIndex: number

      The index of the arguments to check.

    • expected: ExpectedArg

      The expected argument.

    Returns ExpectedArg

    The actual argument.

    import { assertSpyCallArg, spy } from "@std/testing/mock";

    const func = spy((a: number, b: number) => a + b);

    func(3, 4);
    func(5, 6);

    // asserts each call made to the spy function.
    assertSpyCallArg(func, 0, 0, 3);
    assertSpyCallArg(func, 0, 1, 4);
    assertSpyCallArg(func, 1, 0, 5);
    assertSpyCallArg(func, 1, 1, 6);