{"id":"73306fd1e60bb1a8","repo":"jestjs/jest","slug":"the-option-summarythreshold-should-be-a-number","errorCode":null,"errorMessage":"The option summaryThreshold should be a number","messagePattern":"The option summaryThreshold should be a number","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-reporters/src/SummaryReporter.ts","lineNumber":78,"sourceCode":"  static readonly filename = __filename;\n\n  constructor(\n    globalConfig: Config.GlobalConfig,\n    options?: SummaryReporterOptions,\n  ) {\n    super();\n    this._globalConfig = globalConfig;\n    this._estimatedTime = 0;\n    this._validateOptions(options);\n    this._summaryThreshold = options?.summaryThreshold ?? 20;\n  }\n\n  private _validateOptions(options?: SummaryReporterOptions) {\n    if (\n      options?.summaryThreshold &&\n      typeof options.summaryThreshold !== 'number'\n    ) {\n      throw new TypeError('The option summaryThreshold should be a number');\n    }\n  }\n\n  // If we write more than one character at a time it is possible that\n  // Node.js exits in the middle of printing the result. This was first observed\n  // in Node.js 0.10 and still persists in Node.js 6.7+.\n  // Let's print the test failure summary character by character which is safer\n  // when hundreds of tests are failing.\n  private _write(string: string) {\n    for (let i = 0; i < string.length; i++) {\n      process.stderr.write(string.charAt(i));\n    }\n  }\n\n  override onRunStart(\n    aggregatedResults: AggregatedResult,\n    options: ReporterOnStartOptions,\n  ): void {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-reporters/src/SummaryReporter.ts#L60-L96","documentation":"Thrown as a TypeError by SummaryReporter's _validateOptions when options.summaryThreshold is truthy but typeof !== 'number'. summaryThreshold controls how many test suites must run before the failing-test summary is re-printed at the end (default 20 per the constructor). Validation runs in the constructor, so the error surfaces at reporter instantiation — typically at jest startup.","triggerScenarios":"Configuring SummaryReporter with a non-numeric threshold: ['default', ['jest-summary-reporter', {summaryThreshold: '20'}]]; passing a string from an env var without conversion: {summaryThreshold: process.env.SUMMARY_THRESHOLD}; an array or object passed by mistake.","commonSituations":"Reading the threshold from an env var (always a string) without Number(); a config file in JSON/JSONC that quotes the number; copy-paste from documentation that quoted the value.","solutions":["Pass a plain number literal: {summaryThreshold: 50}.","When sourcing from env, convert: {summaryThreshold: Number(process.env.SUMMARY_THRESHOLD) || 20}.","Validate config in a setup script or use a typed config (jest.config.ts) so the editor flags non-numeric values."],"exampleFix":"// before\nreporters: [['jest-summary-reporter', { summaryThreshold: '50' }]]\n// after\nreporters: [['jest-summary-reporter', { summaryThreshold: 50 }]]","handlingStrategy":"validation","validationCode":"function resolveSummaryThreshold(raw: unknown): number {\n  if (raw == null) return 20;\n  if (typeof raw !== 'number' || !Number.isFinite(raw)) {\n    throw new TypeError('summaryThreshold must be a finite number');\n  }\n  return raw;\n}\nconst summaryThreshold = resolveSummaryThreshold(process.env.SUMMARY_THRESHOLD ?? 20);\nreporters: [['<rootDir>/summary-reporter.js', { summaryThreshold }]];","typeGuard":"const isSummaryThreshold = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isFinite(v);\n\nconst opts = isSummaryThreshold(rawThreshold)\n  ? { summaryThreshold: rawThreshold }\n  : { summaryThreshold: 20 };","tryCatchPattern":null,"preventionTips":["Pass summaryThreshold as a bare number literal in config files.","When sourcing from env, wrap with Number() and a fallback.","Use a typed jest.config.ts so non-numeric values are flagged at compile time."],"tags":["jest-reporters","config","type-error","validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}