Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960/** Tests for `arrayOrThrow`. @module */
import { describe, expect, expectTypeOf, it,} from '@monochromatic-dev/module-test/ts';
import { arrayOrThrow, } from '@monochromatic-dev/module-or-throw';
await describe({ name: arrayOrThrow.name, children: [ it({ name: 'returns the value when it is an array', fn: async () => { const arr = [1, 2, 3,]; expect(arrayOrThrow(arr,),).toBe(arr,); const empty: readonly unknown[] = []; expect(arrayOrThrow(empty,),).toBe(empty,); }, },),
it({ name: 'throws on every non-array value', fn: async () => { expect(() => arrayOrThrow('abc',)).toThrow('array',); expect(() => arrayOrThrow(42,)).toThrow('array',); expect(() => arrayOrThrow(null,)).toThrow('array',); expect(() => arrayOrThrow(undefined,)).toThrow('array',); expect(() => arrayOrThrow({ length: 0, },)).toThrow('array',); expect(() => arrayOrThrow(new Set(),)).toThrow('array',); }, },),
it({ name: 'narrows unknown to readonly unknown[]', fn: async () => { const input: unknown = [1, 2,]; const output = arrayOrThrow(input,); expectTypeOf(output,).toEqualTypeOf<readonly unknown[]>(); }, },),
it({ name: 'narrows union to array branch', fn: async () => { const input: string | number[] = [1, 2,]; const output = arrayOrThrow(input,); expectTypeOf(output,).toEqualTypeOf<number[]>(); }, },), ],},);