jestjs/jest · error · TypeError

The option summaryThreshold should be a number

Error message

The option summaryThreshold should be a number

What it means

Thrown by SummaryReporter's _validateOptions (as a TypeError) when the summaryThreshold reporter option is present but not a number. summaryThreshold controls how many failing tests the summary section lists; it must be a numeric value (defaults to 20).

Solutions

  1. Pass a plain number for summaryThreshold (e.g., {summaryThreshold: 50}).
  2. If the value comes from process.env, wrap with Number(...) or parseInt.
  3. Omit the option to accept the default of 20.

Example fix

// before
reporters: [['<rootDir>/SummaryReporter', {summaryThreshold: process.env.SUMMARY_THRESHOLD}]]
// after
reporters: [['<rootDir>/SummaryReporter', {summaryThreshold: Number(process.env.SUMMARY_THRESHOLD) || 20}]]
Defensive patterns

Strategy: validation

Validate before calling

const threshold = options?.summaryThreshold;
if (threshold != null && typeof threshold !== 'number') {
  throw new TypeError('summaryThreshold must be a number');
}

Type guard

const isSummaryThreshold = (x: unknown): x is number =>
  x == null || typeof x === 'number';

Prevention

When it happens

Trigger: Configuring SummaryReporter with ['default', ['<rootDir>/SummaryReporter', {summaryThreshold: '20'}]] or passing a string/boolean/object as summaryThreshold.

Common situations: Reading summaryThreshold from an env var (always a string) without converting; YAML/JSON config accidentally quoting the number; copy-paste from docs that used a string; typo producing an object.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/73306fd1e60bb1a8. Report an issue: GitHub.

Appendix: source

Thrown at packages/jest-reporters/src/SummaryReporter.ts:78

  static readonly filename = __filename;

  constructor(
    globalConfig: Config.GlobalConfig,
    options?: SummaryReporterOptions,
  ) {
    super();
    this._globalConfig = globalConfig;
    this._estimatedTime = 0;
    this._validateOptions(options);
    this._summaryThreshold = options?.summaryThreshold ?? 20;
  }

  private _validateOptions(options?: SummaryReporterOptions) {
    if (
      options?.summaryThreshold &&
      typeof options.summaryThreshold !== 'number'
    ) {
      throw new TypeError('The option summaryThreshold should be a number');
    }
  }

  // If we write more than one character at a time it is possible that
  // Node.js exits in the middle of printing the result. This was first observed
  // in Node.js 0.10 and still persists in Node.js 6.7+.
  // Let's print the test failure summary character by character which is safer
  // when hundreds of tests are failing.
  private _write(string: string) {
    for (let i = 0; i < string.length; i++) {
      process.stderr.write(string.charAt(i));
    }
  }

  override onRunStart(
    aggregatedResults: AggregatedResult,
    options: ReporterOnStartOptions,
  ): void {

View on GitHub (pinned to 8e6d128e4a)