geninq
Version:
A JavaScript version of the Linq library for Generators
32 lines (30 loc) • 729 B
text/typescript
import { It, ItThrows } from "../test-utils";
import "./first";
It("Gets the first element in a sequence", (s) => s.first(), 1);
It(
"Gets the first element in a sequence that matches a predicate",
(s) => s.first((i) => i === 2),
2
);
It(
"Returns undefined if the sequence is empty",
(s) => s.first("or-default"),
undefined,
[]
);
It(
"Returns undefined if the element does not exist",
(s) => s.first((i) => i === 4, "or-default"),
undefined
);
ItThrows(
"Throws for element that does not exist",
(s) => s.first((i) => i === 4),
new Error("No matching elements in sequence.")
);
ItThrows(
"Throws for an empty sequence",
(s) => s.first(),
new Error("No matching elements in sequence."),
[]
);