import {colorText} from '../colorText'; export class ExpectError extends Error { constructor(params: {expected: unknown; received: unknown}) { const {expected, received} = params; const isPrimitiveValue = (value: unknown) => { return typeof value !== 'object'; }; const message = (() => { const shouldIncludeTypeHint = String(expected) === String(received) && isPrimitiveValue(expected) && isPrimitiveValue(received); return ( '\n' + colorText.default('Expected: ') + (shouldIncludeTypeHint ? colorText.grey(`<${typeof expected}>`) : '') + colorText.green(String(expected)) + '\n' + colorText.default('Received: ') + (shouldIncludeTypeHint ? colorText.grey(`<${typeof received}>`) : '') + colorText.red(String(received)) ); })(); super(message); } }