jestjs/jest · error · ValidationError
Option "${path}.${option}" must be of type: ${validTyp
Error message
Option "${path}.${option}" must be of type:
${validTypes}
but instead received:
${getType(received)}
Example:
${formatExamples(option, conditions)} What it means
Thrown by `errorMessage` in jest-validate (errors.ts:24-37, throws as `ValidationError`) when a config option's value fails its type condition. The validator compares the received value's type against the set of types observed across the option's example/default values; on mismatch it prints the expected types, the received type, and a concrete example block.
Source
Thrown at packages/jest-validate/src/errors.ts:37
path?: Array<string>,
): void => {
const conditions = getValues(defaultValue);
const validTypes: Array<string> = [...new Set(conditions.map(getType))];
const message = ` Option ${chalk.bold(
`"${path && path.length > 0 ? `${path.join('.')}.` : ''}${option}"`,
)} must be of type:
${validTypes.map(e => chalk.bold.green(e)).join(' or ')}
but instead received:
${chalk.bold.red(getType(received))}
Example:
${formatExamples(option, conditions)}`;
const comment = options.comment;
const name = (options.title && options.title.error) || ERROR;
throw new ValidationError(name, message, comment);
};
function formatExamples(option: string, examples: Array<unknown>) {
return examples.map(
e => ` {
${chalk.bold(`"${option}"`)}: ${chalk.bold(formatPrettyObject(e))}
}`,
).join(`
or
`);
}
View on GitHub (pinned to f49721c78e)
Solutions
- Read the message's `must be of type` line and the example block - they name the exact shape expected.
- Open the Jest config docs for the named option and match the documented type.
- Run Jest with `--showConfig` or `--listTests` to surface validation before running tests.
- If overriding via env vars (e.g. `--maxWorkers`), ensure CLI/coercion produces the right type.
Example fix
// before
module.exports = { coverageThreshold: { global: 'lines' } }; // 'lines' should be a number
// after
module.exports = { coverageThreshold: { global: { lines: 80 } } }; Defensive patterns
Strategy: validation
Validate before calling
// Validate config types against the example/default before running Jest
const { validate } = require('jest-validate');
validate(myConfig, { exampleConfig: defaultJestConfig, title: { warn: '', error: 'jest.config.js' } }); Type guard
const isObjectType = (v: unknown, t: 'object' | 'string' | 'number' | 'boolean' | 'function'): boolean => t === 'object' ? (typeof v === 'object' && v !== null && !Array.isArray(v)) : typeof v === t;
Prevention
- Cross-check each option's type in the Jest config docs before writing it.
- Use TypeScript-typed jest config (`/** @type {import('jest').Config} */`).
- Run `jest --showConfig` to validate before executing the suite.
When it happens
Trigger: Setting a Jest config option to a value whose runtime type doesn't match any of the types present in the default/example config: e.g. coverageThreshold set to a string instead of object, testMatch set to a single string instead of an array of strings (testMatch is array-typed), coveragePathIgnorePatterns set to a single string instead of an array.
Common situations: Hand-typed jest.config.js where the shape doesn't match the docs; copy-pasting a single value where Jest wants an array (or vice versa); passing a function where a value is expected; environment-variable overrides coerced to the wrong type.
Related errors
- ${key} has to be of type string or number
- The option summaryThreshold should be a number
- Custom snapshot resolver must implement a `${propName}` as a
- ● Invalid transformer module: "${slash(transformPath)}" sp
- Invalid first argument, ${descriptor}. It must be a named cl
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/b1d1e8c6b775c894.json.
Report an issue: GitHub.