Function assertSpyCallAsync

  • Asserts that an async spy is called 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.

    Parameters

    Returns Promise<void>

    import { assertSpyCallAsync, spy } from "@std/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 });