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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123/** Tests for the input validation error class. @module */
import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { InvalidInputError, pify,} from '../dist/final/neutral/index.mjs';
await describe({ name: '', children: [ describe({ name: InvalidInputError.name, children: [ it({ name: 'extends TypeError so existing TypeError handlers keep working', fn: async () => { const error = new InvalidInputError('nope',); expect(error,).toBeInstanceOf(TypeError,); expect(error,).toBeInstanceOf(Error,); }, },),
it({ name: 'names itself for readable stacks', fn: async () => { const error = new InvalidInputError('nope',); expect(error.name,).toBe('InvalidInputError',); }, },),
it({ name: 'carries upstream pify message text for null input', fn: async () => { const error = new InvalidInputError(null,); expect( error.message, ).toBe('Expected `input` to be a `Function` or `Object`, got `null`',); }, },),
it({ name: 'carries upstream pify message text for undefined input', fn: async () => { const error = new InvalidInputError(undefined,); expect( error.message, ).toBe('Expected `input` to be a `Function` or `Object`, got `undefined`',); }, },),
it({ name: 'reports typeof strings for primitive input, like upstream', fn: async () => { /** Inputs paired with the `typeof` string upstream's message shows. */ const cases: readonly { readonly input: unknown; readonly shown: string; }[] = [ { input: '', shown: 'string', }, { input: 3, shown: 'number', }, { input: true, shown: 'boolean', }, { input: 1n, shown: 'bigint', }, { input: Symbol('sample member key for message text',), shown: 'symbol', }, ]; for (const { input, shown, } of cases) { const error = new InvalidInputError(input,); expect( error.message, ).toBe(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${shown}\``,); } }, },),
it({ name: 'pify throws it for non-function, non-object input', fn: async () => { /** Last error thrown by `pify` on invalid input, captured for its message comparison. */ let thrown: unknown; try { // @ts-expect-error -- upstream `pify` accepts invalid input at runtime and throws its TypeError there; the overload surface correctly rejects it pify({ input: null, },); } catch (error) { thrown = error; } expect(thrown,).toBeInstanceOf(InvalidInputError,); expect( (thrown as InvalidInputError).message, ).toBe('Expected `input` to be a `Function` or `Object`, got `null`',); }, },), ], },), ],},);