jestjs/jest · error · Error
Attempted to display seed but seed value is undefined
Error message
Attempted to display seed but seed value is undefined
What it means
Thrown by jest-reporters' getSummary() at packages/jest-reporters/src/getSummary.ts:122 when the caller requests seed display (options.showSeed === true) but supplies no seed value (options.seed === undefined). Jest prints a 'Seed: <n>' line in the test summary so that randomized runs can be reproduced; if you ask for that line without giving it a number to print, the function aborts rather than emit a misleading empty seed. It is a hard guard against rendering an undefined value into the summary output.
Source
Thrown at packages/jest-reporters/src/getSummary.ts:122
const snapshotsUpdated = snapshotResults.updated;
const suitesFailed = aggregatedResults.numFailedTestSuites;
const suitesPassed = aggregatedResults.numPassedTestSuites;
const suitesPending = aggregatedResults.numPendingTestSuites;
const suitesRun = suitesFailed + suitesPassed;
const suitesTotal = aggregatedResults.numTotalTestSuites;
const testsFailed = aggregatedResults.numFailedTests;
const testsPassed = aggregatedResults.numPassedTests;
const testsPending = aggregatedResults.numPendingTests;
const testsTodo = aggregatedResults.numTodoTests;
const testsTotal = aggregatedResults.numTotalTests;
const width = (options && options.width) || 0;
const optionalLines: Array<string> = [];
if (options?.showSeed === true) {
const {seed} = options;
if (seed === undefined) {
throw new Error('Attempted to display seed but seed value is undefined');
}
optionalLines.push(`${chalk.bold('Seed: ') + seed}`);
}
const suites = `${
chalk.bold('Test Suites: ') +
(suitesFailed ? `${chalk.bold.red(`${suitesFailed} failed`)}, ` : '') +
(suitesPending
? `${chalk.bold.yellow(`${suitesPending} skipped`)}, `
: '') +
(suitesPassed ? `${chalk.bold.green(`${suitesPassed} passed`)}, ` : '') +
(suitesRun === suitesTotal ? suitesTotal : `${suitesRun} of ${suitesTotal}`)
} total`;
const updatedTestsFailed =
testsFailed + valuesForCurrentTestCases.numFailingTests;
const updatedTestsPending =
testsPending + valuesForCurrentTestCases.numPendingTests;View on GitHub (pinned to 8e6d128e4a)
Solutions
- Enable randomized ordering so Jest generates and stores a seed: pass --randomize on the CLI or set `randomize: true` in jest.config.js (this auto-populates globalConfig.seed and pairs naturally with --showSeed).
- Supply an explicit seed: pass --seed=<n> on the CLI or set `seed: <number>` in jest.config.js so globalConfig.seed is defined.
- Remove `showSeed: true` from your Jest config / reporter options if you do not actually need the Seed line in the summary.
- If calling getSummary directly in a custom reporter, always pass both together: `{showSeed: globalConfig.showSeed, seed: globalConfig.seed}` and guard `showSeed: Boolean(globalConfig.showSeed) && globalConfig.seed !== undefined` before enabling it.
Example fix
// before (jest.config.js)
module.exports = {
showSeed: true,
// no randomize, no seed -> error at getSummary.ts:122
};
// after: enable randomize so a seed is generated
module.exports = {
randomize: true,
showSeed: true,
};
// or: pin an explicit seed
module.exports = {
seed: 12345,
showSeed: true,
}; Defensive patterns
Strategy: validation
Validate before calling
// Before calling getSummary, normalise the options so showSeed is only
// true when a numeric seed actually exists.
import type {SummaryOptions} from 'jest-reporters';
function safeSummaryOptions(opts: SummaryOptions): SummaryOptions {
const showSeed = opts.showSeed === true && typeof opts.seed === 'number';
return {...opts, showSeed};
}
// usage
const summary = getSummary(aggregatedResults, safeSummaryOptions({
showSeed: globalConfig.showSeed,
seed: globalConfig.seed,
estimatedTime,
})); Type guard
// Type + runtime guard narrowing: showSeed truthy implies seed is a number.
type SafeSummaryOptions =
| ({showSeed?: false} & SummaryOptions)
| ({showSeed: true; seed: number} & SummaryOptions);
function hasSeed(opts: SummaryOptions): opts is {showSeed: true; seed: number} {
return opts.showSeed === true && typeof opts.seed === 'number' && Number.isFinite(opts.seed);
}
if (hasSeed(options)) {
// safe to call getSummary with options.showSeed === true
} Try / catch
// For custom reporters that wrap getSummary: catch, surface via _setError,
// and re-run without showSeed so the summary still renders.
try {
message = getSummary(aggregatedResults, {showSeed: true, seed: globalConfig.seed});
} catch (e) {
this._setError(e as Error);
message = getSummary(aggregatedResults, {showSeed: false});
} Prevention
- Treat --showSeed and --randomize (or an explicit --seed) as a single feature: never enable showSeed without a seed source.
- In jest.config.js, set `randomize: true` alongside `showSeed: true` so Jest always generates a seed to print.
- In custom reporters, thread both globalConfig.showSeed and globalConfig.seed together and coerce showSeed to false when seed is missing.
- Add a unit test mirroring __tests__/getSummary.test.ts:32 that asserts the throwing case AND the safe-passthrough case for your reporter options.
- When upgrading Jest across versions that introduced seed support, audit globalConfig usage in any reporter you maintain for unset seed fields.
When it happens
Trigger: Calling getSummary(aggregatedResults, {showSeed: true}) without a numeric seed property. In the CLI/runtime path, SummaryReporter._printTestRunEnd (SummaryReporter.ts:125-129) forwards globalConfig.showSeed and globalConfig.seed, so the error fires when globalConfig.showSeed is true while globalConfig.seed is undefined. Concretely: running jest with --showSeed but no --seed=<n> and no --randomize (which would auto-generate a seed), or setting `showSeed: true` in jest.config without `randomize: true` or `seed: <n>`. Also when invoking getSummary directly from a custom reporter.
Common situations: A developer adds `showSeed: true` to a Jest config or custom reporter to surface the seed for reproducible test ordering, but forgets that a seed is only present when `randomize: true` or an explicit `seed` is configured. Another common case: upgrading Jest and adopting the newer --showSeed flag while the project does not use randomized ordering, leaving globalConfig.seed undefined. Custom reporters that wrap getSummary and hardcode showSeed: true without threading the seed through are the third typical source.
Related errors
- seed value must be between `-0x80000000` and `0x7fffffff` in
- babel-jest: Babel ignores ${chalk.bold(slash(path.relative(c
- Could not find a "package.json" file in ${rootDir}
- ${EXPECTED_COLOR('expected')} value must be a number
- ${RECEIVED_COLOR('received')} value must be a number
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/d71a01efe3608bbe.
Report an issue: GitHub.