{"id":"f57d458d6aa74c9e","repo":"vitest-dev/vitest","slug":"expected-config-test-coverage-thresholds-to-be-an","errorCode":null,"errorMessage":"Expected config.test.coverage.thresholds to be an object","messagePattern":"Expected config\\.test\\.coverage\\.thresholds to be an object","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/coverage.ts","lineNumber":862,"sourceCode":"      'functions' in thresholds && typeof thresholds.functions === 'number'\n        ? thresholds.functions\n        : undefined,\n    statements:\n      'statements' in thresholds && typeof thresholds.statements === 'number'\n        ? thresholds.statements\n        : undefined,\n  }\n}\n\nfunction assertConfigurationModule(config: unknown): asserts config is {\n  test: {\n    coverage: { thresholds: NonNullable<CoverageOptions['thresholds']> }\n  }\n} {\n  try {\n    // @ts-expect-error -- Intentional unsafe null pointer check as wrapped in try-catch\n    if (typeof config.test.coverage.thresholds !== 'object') {\n      throw new TypeError(\n        'Expected config.test.coverage.thresholds to be an object',\n      )\n    }\n  }\n  catch (error) {\n    const message = error instanceof Error ? error.message : String(error)\n    throw new Error(\n      `Unable to parse thresholds from configuration file: ${message}`,\n    )\n  }\n}\n\nfunction resolveConfig(configModule: any) {\n  const mod = configModule.exports.default\n\n  try {\n    // Check for \"export default { test: {...} }\"\n    if (mod.$type === 'object') {","sourceCodeStart":844,"sourceCodeEnd":880,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/coverage.ts#L844-L880","documentation":"resolveThresholds (coverage.ts:862) asserts that config.test.coverage.thresholds is an object before reading its keys. Anything else (boolean, array, number, undefined when autoUpdate walks the config file) throws a TypeError.","triggerScenarios":"Config file (or magicast-parsed module) has coverage.thresholds set to a non-object value such as true, null, or an array, and vitest tries to read/update thresholds from it.","commonSituations":"Setting thresholds: true as a shortcut; copying partial config from docs; autoUpdate walking a misshapen config.","solutions":["Set coverage.thresholds to an object, e.g. { lines: 80, functions: 80, branches: 75, statements: 80 }.","Remove the thresholds key entirely if you don't enforce thresholds.","Re-run after fixing; the message tells you exactly what failed."],"exampleFix":"// before\ntest: { coverage: { thresholds: true } }\n\n// after\ntest: { coverage: { thresholds: { lines: 80, functions: 80 } } }","handlingStrategy":"type-guard","validationCode":"const t = config.test?.coverage?.thresholds\nif (t != null && (typeof t !== 'object' || Array.isArray(t))) {\n  throw new TypeError('coverage.thresholds must be an object')\n}","typeGuard":"function isThresholdsObject(t: unknown): t is Record<string, number> {\n  return t != null && typeof t === 'object' && !Array.isArray(t)\n}","tryCatchPattern":null,"preventionTips":["Define thresholds as an object { lines, functions, branches, statements }.","Validate the config with a schema/zod check in CI.","Avoid shorthand like thresholds: true."],"tags":["coverage","thresholds","config","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}