assertSpyCallArgs

import { assertSpyCallArgs } from "jsr:@ende/testing/mock";

function

function assertSpyCallArgs<Self, Args extends unknown[], Return, ExpectedArgs extends unknown[]>(spy: SpyLike<Self, Args, Return>, callIndex: number, expected: ExpectedArgs): ExpectedArgs

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.

spy: SpyLike<Self, Args, Return>

The spy to check.

callIndex: number

The index of the call to check.

expected: ExpectedArgs

The expected arguments.

Returns

The actual arguments.

Example: Usage

import { assertSpyCallArgs, spy } from "@ende/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]);

function

function assertSpyCallArgs<Self, Args extends unknown[], Return, ExpectedArgs extends unknown[]>(spy: SpyLike<Self, Args, Return>, callIndex: number, argsStart: number, expected: ExpectedArgs): ExpectedArgs

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.

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

The actual arguments.

Example: Usage

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

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

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

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

function

function assertSpyCallArgs<Self, Args extends unknown[], Return, ExpectedArgs extends unknown[]>(spy: SpyLike<Self, Args, Return>, callIndex: number, argsStart: number, argsEnd: number, expected: ExpectedArgs): ExpectedArgs

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.

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

The actual arguments

Example: Usage

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

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

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

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

function

function assertSpyCallArgs<ExpectedArgs extends unknown[], Args extends unknown[], Return, Self>(spy: SpyLike<Self, Args, Return>, callIndex: number, argsStart?: number | ExpectedArgs, argsEnd?: number | ExpectedArgs, expected?: ExpectedArgs): ExpectedArgs

Source