Function assertSpyCallArgs

  • Asserts that an spy is called with a specific range of args as expected. If a start and end index is not provided, the expected will be compared against all args. If a start is provided without an end index, the expected will be compared against all args from the start index to the end. The end index is not included in the range of args that are compared.

    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.

    • ExpectedArgs extends unknown[]

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

    Parameters

    Returns ExpectedArgs

    The actual arguments.

    import { assertSpyCallArgs, 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.
    assertSpyCallArgs(func, 0, [3, 4]);
    assertSpyCallArgs(func, 1, [5, 6]);
  • Asserts that an spy is called with a specific range of args as expected. If a start and end index is not provided, the expected will be compared against all args. If a start is provided without an end index, the expected will be compared against all args from the start index to the end. The end index is not included in the range of args that are compared.

    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.

    • ExpectedArgs extends unknown[]

      The expected type of the arguments 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.

    • argsStart: number

      The start index of the arguments to check. If not specified, it checks the arguments from the beignning.

    • expected: ExpectedArgs

      The expected arguments.

    Returns ExpectedArgs

    The actual arguments.

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

    const func = spy((...args) => {});

    func(0, 1, 2, 3, 4, 5);

    assertSpyCallArgs(func, 0, 3, [3, 4, 5]);
  • Asserts that an spy is called with a specific range of args as expected. If a start and end index is not provided, the expected will be compared against all args. If a start is provided without an end index, the expected will be compared against all args from the start index to the end. The end index is not included in the range of args that are compared.

    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.

    • ExpectedArgs extends unknown[]

      The expected type of the arguments 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

    • argsStart: number

      The start index of the arguments to check. If not specified, it checks the arguments from the beignning.

    • argsEnd: number

      The end index of the arguments to check. If not specified, it checks the arguments until the end.

    • expected: ExpectedArgs

      The expected arguments.

    Returns ExpectedArgs

    The actual arguments

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

    const func = spy((...args) => {});

    func(0, 1, 2, 3, 4, 5);

    assertSpyCallArgs(func, 0, 3, 4, [3]);