vitest-dev/vitest · error · Error

pretty-format: Unknown option

Error message

pretty-format: Unknown option "${key}".

What it means

validateOptions rejects any option key not present in DEFAULT_OPTIONS before formatting. This catches typos and unsupported option names early, listing the offending key.

Example fix

// before
format(value, { highlight: true, indent: 2 })
// after
format(value, { highlight: true, indent: 2 }.hasOwnProperty('highlight') ? { highlight: true } : {})
Defensive patterns

Strategy: validation

Validate before calling

import { DEFAULT_OPTIONS } from 'pretty-format'
const KNOWN = new Set(Object.keys(DEFAULT_OPTIONS))
for (const k of Object.keys(userOptions)) {
  if (!KNOWN.has(k)) throw new Error(`unknown pretty-format option '${k}'`)
}
format(value, userOptions)

Type guard

function isKnownOption(key: string): boolean { return Object.hasOwn(DEFAULT_OPTIONS, key) }

Prevention

When it happens

Trigger: Calling format(value, { highlight: true }) or format(value, { indent: 2, pretty: true }) where 'highlight'/'pretty' are not valid keys; passing a misspelled option like 'maxDepth' instead of 'maxDepth'-equivalent.

Common situations: Copy-pasting options from another library (e.g. Jest's older option names); typo in an option name; passing options intended for a different formatter.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/f0d40956478f91dd. Report an issue: GitHub.

Appendix: source

Thrown at packages/pretty-format/src/index.ts:471

  // (Node's limit is buffer.constants.MAX_STRING_LENGTH ~ 512MB)
  maxOutputLength: 1_000_000,
  maxWidth: Number.POSITIVE_INFINITY,
  min: false,
  plugins: [],
  printBasicPrototype: true,
  printFunctionName: true,
  printShadowRoot: true,
  theme: DEFAULT_THEME,
  singleQuote: false,
  quoteKeys: true,
  spacingInner: '\n',
  spacingOuter: '\n',
} satisfies Options

function validateOptions(options: OptionsReceived) {
  for (const key of Object.keys(options)) {
    if (!Object.hasOwn(DEFAULT_OPTIONS, key)) {
      throw new Error(`pretty-format: Unknown option "${key}".`)
    }
  }

  if (options.min && options.indent !== undefined && options.indent !== 0) {
    throw new Error(
      'pretty-format: Options "min" and "indent" cannot be used together.',
    )
  }
}

function getColorsHighlight(): Colors {
  return DEFAULT_THEME_KEYS.reduce((colors, key) => {
    const value = DEFAULT_THEME[key]
    const color = value && (styles as any)[value]
    if (
      color
      && typeof color.close === 'string'
      && typeof color.open === 'string'

View on GitHub (pinned to 1fa9837ec2)