assertSpyCallAsync
import { assertSpyCallAsync } from "jsr:@ende/testing/mock";function
async function assertSpyCallAsync<Self, Args extends unknown[], Return>(spy: SpyLike<Self, Args, Promise<Return>>, callIndex: number, expected?: ExpectedSpyCall<Self, Args, Promise<Return> | Return>): Promise<void>Asserts that an async spy is called as expected.
spy: SpyLike<Self, Args, Promise<Return>>The spy to check
callIndex: numberThe index of the call to check
expected?: ExpectedSpyCall<Self, Args, Promise<Return> | Return>The expected spy call.
Example: Usage
import { assertSpyCallAsync, spy } from "@ende/testing/mock";
const func = spy((a: number, b: number) => new Promise((resolve) => {
setTimeout(() => resolve(a + b), 100)
}));
await func(3, 4);
await func(5, 6);
// asserts each call made to the spy function.
await assertSpyCallAsync(func, 0, { args: [3, 4], returned: 7 });
await assertSpyCallAsync(func, 1, { args: [5, 6], returned: 11 });