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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768/** Tests for `objectOrThrow`. @module */
import { describe, expect, expectTypeOf, it,} from '@monochromatic-dev/module-test/ts';
import { objectOrThrow, } from '@monochromatic-dev/module-or-throw';
await describe({ name: objectOrThrow.name, children: [ it({ name: 'returns plain objects, arrays, and class instances unchanged', fn: async () => { const obj = { a: 1, }; expect(objectOrThrow(obj,),).toBe(obj,); const arr: unknown[] = []; expect(objectOrThrow(arr,),).toBe(arr,); const map = new Map(); expect(objectOrThrow(map,),).toBe(map,); }, },),
it({ name: 'throws on null', fn: async () => { expect(() => objectOrThrow(null,)).toThrow('non-null object',); }, },),
it({ name: 'throws on primitives', fn: async () => { expect(() => objectOrThrow(0,)).toThrow('non-null object',); expect(() => objectOrThrow('abc',)).toThrow('non-null object',); expect(() => objectOrThrow(true,)).toThrow('non-null object',); expect(() => objectOrThrow(undefined,)).toThrow('non-null object',); expect(() => objectOrThrow(Symbol('non object symbol value',),)).toThrow('non-null object',); expect(() => objectOrThrow(1n,)).toThrow('non-null object',); }, },),
it({ name: 'throws on functions (functions are typeof "function", not "object")', fn: async () => { function noop(): void {} expect(() => objectOrThrow(noop,)).toThrow('non-null object',); }, },),
it({ name: 'narrows unknown to object', fn: async () => { const input: unknown = { a: 1, }; const output = objectOrThrow(input,); expectTypeOf(output,).toEqualTypeOf<object>(); }, },), ],},);