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.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970/** Tests for `functionOrThrow`. @module */
import { describe, expect, expectTypeOf, it,} from '@monochromatic-dev/module-test/ts';
import { functionOrThrow, } from '@monochromatic-dev/module-or-throw';
function double(n: number,): number { return n * 2;}
async function asyncOne(): Promise<number> { return 1;}
function* yieldOne(): Generator<number> { yield 1;}
function noop(): void {}
await describe({ name: functionOrThrow.name, children: [ it({ name: 'returns named function declarations unchanged', fn: async () => { expect(functionOrThrow(double,),).toBe(double,); }, },),
it({ name: 'returns async, generator, and built-in functions unchanged', fn: async () => { expect(functionOrThrow(asyncOne,),).toBe(asyncOne,); expect(functionOrThrow(yieldOne,),).toBe(yieldOne,); expect(functionOrThrow(Array.from,),).toBe(Array.from,); }, },),
it({ name: 'throws on non-callable values', fn: async () => { expect(() => functionOrThrow({},)).toThrow('function',); expect(() => functionOrThrow([],)).toThrow('function',); expect(() => functionOrThrow('fn',)).toThrow('function',); expect(() => functionOrThrow(null,)).toThrow('function',); expect(() => functionOrThrow(undefined,)).toThrow('function',); }, },),
it({ name: 'narrows unknown to a callable type', fn: async () => { const input: unknown = noop; const output = functionOrThrow(input,); expectTypeOf(output,).toBeFunction(); }, },), ],},);