{"record":{"id":"b4e11309c4d41d85","repo":"jestjs/jest","slug":"received-color-received-value-must-be-a-numb-b4e113","errorCode":null,"errorMessage":"${RECEIVED_COLOR('received')} 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":186,"sourceCode":"        'this matcher must not have an expected argument',\n        printWithType('Expected', expected, printExpected),\n      ),\n    );\n  }\n};\n\n/**\n * Ensures that `actual` is of type `number | bigint`\n */\nexport const ensureActualIsNumber = (\n  actual: unknown,\n  matcherName: string,\n  options?: MatcherHintOptions,\n): void => {\n  if (typeof actual !== 'number' && typeof actual !== '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        `${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') {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-matcher-utils/src/index.ts#L168-L204","documentation":"Thrown by ensureActualIsNumber in jest-matcher-utils when the received value is not a number or bigint (index.ts:183-193). Numeric matchers (toBeGreaterThan, toBeLessThan, toBeCloseTo, etc.) guard their inputs because they perform arithmetic comparisons; a non-numeric actual would produce NaN-driven nonsense results rather than a clear failure.","triggerScenarios":"expect('10').toBeGreaterThan(5), expect(undefined).toBeCloseTo(1), expect(NaN).toBeLessThan(5), expect({val:1}).toBeGreaterThan(0), or expect('0x10').toBeGreaterThan(1) where a string is passed instead of a parsed number.","commonSituations":"Forgetting to parse numeric strings from env vars or DOM inputs; consuming an API that returns stringified numbers; undefined returned from a stubbed function; refactor that changed a return type from number to string; BigInt/Number mixing.","solutions":["Coerce or parse before asserting: expect(Number(x)).toBeGreaterThan(5) or expect(parseInt(x, 10)).toBeGreaterThan(5).","Fix the source so the value is actually a number: change the function return type and serialisation.","Add a type guard or earlier assertion: expect(typeof x).toBe('number').","If NaN is possible, guard explicitly: if (Number.isNaN(x)) throw ... or assert with expect(x).not.toBeNaN()."],"exampleFix":"// before\nexpect(getCountStr()).toBeGreaterThan(5); // returns '10'\n// after\nexpect(Number(getCountStr())).toBeGreaterThan(5);","handlingStrategy":"type-guard","validationCode":"if (typeof actual !== 'number' && typeof actual !== 'bigint') {\n  throw new TypeError('Numeric matcher requires a number or bigint actual');\n}\nexpect(actual).toBeGreaterThan(expected);","typeGuard":"const isNumeric = (v: unknown): v is number | bigint =>\n  typeof v === 'number' || typeof v === 'bigint';","tryCatchPattern":null,"preventionTips":["Parse numeric strings before asserting.","Guard against NaN with Number.isNaN.","Fix source APIs to return numbers, not stringified numbers."],"tags":["jest","matcher","assertion","numeric","type-error","api-misuse"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}