import { createMatcher } from "../../match/match.js"; import { desc, repr } from "../../describe/describe.js"; import { arrayIncludingMatcher, type ArrayIncluding, type ArrayIncludingMatcher, } from "./array-includes.type.js"; /** * Matcher for an array including a specific single element. */ export function arrayIncluding(element: E): ArrayIncludingMatcher { return { ...createMatcher( (value): value is ArrayIncluding => Array.isArray(value) && value.includes(element), () => `array including ${desc(element)}`, () => `[…,${repr(element)},…]`, ), // Runtime marker used only to make the matcher type nominal for type-level // refinement dispatch. It is not part of the user-facing matcher behaviour. [arrayIncludingMatcher]: element, }; }