{"record":{"id":"fb716246f878814c","repo":"jestjs/jest","slug":"expected-color-expected-value-must-be-a-numb-fb7162","errorCode":null,"errorMessage":"${EXPECTED_COLOR('expected')} value must be a number or bigint","messagePattern":"(.+?) value must be a number or bigint","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-matcher-utils/src/index.ts","lineNumber":207,"sourceCode":"        `${RECEIVED_COLOR('received')} value must be a number or bigint`,\n        printWithType('Received', actual, printReceived),\n      ),\n    );\n  }\n};\n\n/**\n * Ensures that `expected` is of type `number | bigint`\n */\nexport const ensureExpectedIsNumber = (\n  expected: unknown,\n  matcherName: string,\n  options?: MatcherHintOptions,\n): void => {\n  if (typeof expected !== 'number' && typeof expected !== 'bigint') {\n    // Prepend maybe not only for backward compatibility.\n    const matcherString = (options ? '' : '[.not]') + matcherName;\n    throw new Error(\n      matcherErrorMessage(\n        matcherHint(matcherString, undefined, undefined, options),\n        `${EXPECTED_COLOR('expected')} value must be a number or bigint`,\n        printWithType('Expected', expected, printExpected),\n      ),\n    );\n  }\n};\n\n/**\n * Ensures that `actual` & `expected` are of type `number | bigint`\n */\nexport const ensureNumbers = (\n  actual: unknown,\n  expected: unknown,\n  matcherName: string,\n  options?: MatcherHintOptions,\n): void => {","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-matcher-utils/src/index.ts#L189-L225","documentation":"Thrown by ensureExpectedIsNumber in jest-matcher-utils, a guard invoked by Jest's numeric comparison matchers (toBeGreaterThan,toBeLessThan,toBeGreaterThanOrEqual,toBeLessThanOrEqual,toBeCloseTo). It validates the `expected` argument is `number` or `bigint` before performing the comparison so the matcher fails fast with a clear message instead of producing a misleading pass/fail from coercion.","triggerScenarios":"Calling a numeric matcher whose expected value is not a number/bigint: expect(value).toBeGreaterThan('10'), expect(n).toBeLessThan(undefined), expect(big).toBeGreaterThan(JSON.parse('\\\"1\\\"')).","commonSituations":"Passing an unparsed string from process.env or a config file; comparing against an import that resolved to undefined because of a wrong/ESM-CJS path; mixing JSON-parsed values (which turn bigints into strings); typo in a variable name yielding undefined.","solutions":["Coerce the expected value with Number(...), parseInt, or parseFloat before the matcher.","Verify any imported/config variable used as the expected bound is actually defined (log it).","If comparing BigInts produced from JSON, rehydrate them with BigInt(...) instead of leaving a string."],"exampleFix":"// before\nexpect(cpu).toBeGreaterThan(config.threshold);\n// after\nexpect(cpu).toBeGreaterThan(Number(config.threshold));","handlingStrategy":"validation","validationCode":"if (typeof expected !== 'number' && typeof expected !== 'bigint') {\n  throw new TypeError(`expected bound must be number|bigint, got ${typeof expected}`);\n}\nexpect(value).toBeGreaterThan(expected);","typeGuard":"const isNumberOrBigInt = (x: unknown): x is number | bigint =>\n  typeof x === 'number' || typeof x === 'bigint';","tryCatchPattern":null,"preventionTips":["Always coerce config/env values to Number before using them as matcher bounds.","Type expected bounds explicitly as number in your helper signatures.","Run TypeScript with strict checks so non-numeric bounds are flagged at compile time."],"tags":["matcher","type-validation","numeric"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}