returnsNext

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

function

function returnsNext<Return, Self = any, Args extends unknown[] = any[]>(values: Iterable<Return | Error>): (this: Self, ...args: Args) => Return

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

values: Iterable<Return | Error>

The iterable values

Returns

A function that returns the iterable values

Example: Usage

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

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

Source