( values: Iterable<Return | Error>, )
| 1730 | * @return A function that returns the iterable values |
| 1731 | */ |
| 1732 | export function returnsNext< |
| 1733 | Return, |
| 1734 | // deno-lint-ignore no-explicit-any |
| 1735 | Self = any, |
| 1736 | // deno-lint-ignore no-explicit-any |
| 1737 | Args extends unknown[] = any[], |
| 1738 | >( |
| 1739 | values: Iterable<Return | Error>, |
| 1740 | ): (this: Self, ...args: Args) => Return { |
| 1741 | const gen = (function* returnsValue() { |
| 1742 | yield* values; |
| 1743 | })(); |
| 1744 | let calls = 0; |
| 1745 | return function () { |
| 1746 | const next = gen.next(); |
| 1747 | if (next.done) { |
| 1748 | throw new MockError( |
| 1749 | `Not expected to be called more than ${calls} time(s)`, |
| 1750 | ); |
| 1751 | } |
| 1752 | calls++; |
| 1753 | const { value } = next; |
| 1754 | if (value instanceof Error) throw value; |
| 1755 | return value; |
| 1756 | }; |
| 1757 | } |
| 1758 | |
| 1759 | /** |
| 1760 | * Creates a function that resolves the awaited iterable values. Any awaited iterable values that are errors will be thrown. |
no test coverage detected