Function returnsNext

  • Creates a function that returns the iterable values. Any iterable values that are errors will be thrown.

    Type Parameters

    • Return

      The type of each item of the iterable

    • Self = any

      The self type of the returned function

    • Args extends unknown[] = any[]

      The arguments type of the returned function

    Parameters

    • values: Iterable<Return | Error, any, any>

      The iterable values

    Returns ((this: Self, ...args: Args) => Return)

    A function that returns the iterable values

    import { returnsNext } from "@std/testing/mock";
    import { assertEquals, assertThrows } from "@std/assert";

    const func = returnsNext([1, 2, new Error("foo"), 3]);
    assertEquals(func(), 1);
    assertEquals(func(), 2);
    assertThrows(() => func(), Error, "foo");
    assertEquals(func(), 3);