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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657/** Tests for `numericOrThrow`. @module */
import { describe, expect, expectTypeOf, it,} from '@monochromatic-dev/module-test/ts';
import { numericOrThrow, } from '@monochromatic-dev/module-or-throw';
await describe({ name: numericOrThrow.name, children: [ it({ name: 'returns primitive numbers unchanged', fn: async () => { expect(numericOrThrow(42,),).toBe(42,); expect(numericOrThrow(0,),).toBe(0,); expect(numericOrThrow(-1.5,),).toBe(-1.5,); }, },),
it({ name: 'returns primitive bigints unchanged', fn: async () => { expect(numericOrThrow(42n,),).toBe(42n,); expect(numericOrThrow(0n,),).toBe(0n,); }, },),
it({ name: 'throws on non-numeric values', fn: async () => { expect(() => numericOrThrow('42',)).toThrow('number or bigint',); expect(() => numericOrThrow(true,)).toThrow('number or bigint',); expect(() => numericOrThrow(null,)).toThrow('number or bigint',); expect(() => numericOrThrow(undefined,)).toThrow('number or bigint',); expect(() => numericOrThrow({},)).toThrow('number or bigint',); }, },),
it({ name: 'narrows unknown to number | bigint', fn: async () => { const input: unknown = 42; const output = numericOrThrow(input,); expectTypeOf(output,).toEqualTypeOf<number | bigint>(); }, },), ],},);