{"record":{"id":"b8897cbd14639411","repo":"jestjs/jest","slug":"precision-is-not-a-number","errorCode":null,"errorMessage":"Precision is not a Number","messagePattern":"Precision is not a Number","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/expect/src/asymmetricMatchers.ts","lineNumber":355,"sourceCode":"  toString() {\n    return `String${this.inverse ? 'Not' : ''}Matching`;\n  }\n\n  override getExpectedType() {\n    return 'string';\n  }\n}\n\nclass CloseTo extends AsymmetricMatcher<number> {\n  private readonly precision: number;\n\n  constructor(sample: number, precision = 2, inverse = false) {\n    if (!isA('Number', sample)) {\n      throw new Error('Expected is not a Number');\n    }\n\n    if (!isA('Number', precision)) {\n      throw new Error('Precision is not a Number');\n    }\n\n    super(sample);\n    this.inverse = inverse;\n    this.precision = precision;\n  }\n\n  asymmetricMatch(other: unknown) {\n    if (!isA<number>('Number', other)) {\n      return false;\n    }\n    let result: boolean;\n    if (\n      other === Number.POSITIVE_INFINITY &&\n      this.sample === Number.POSITIVE_INFINITY\n    ) {\n      result = true; // Infinity - Infinity is NaN\n    } else if (","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/expect/src/asymmetricMatchers.ts#L337-L373","documentation":"CloseTo's second constructor argument, precision (default 2), must be a Number; the constructor throws an Error if it is not. Precision controls the tolerance (10^-precision / 2) for the floating-point comparison, so a non-numeric precision would make the comparison meaningless.","triggerScenarios":"Calling `expect.closeTo(value, precision)` where precision is a non-number (e.g. a string like '3', undefined passed positionally, or an object). Thrown at construction time.","commonSituations":"Passing precision as a string from config; forgetting the default and passing an undefined second arg explicitly; off-by-one argument ordering where precision lands in the wrong slot.","solutions":["Omit precision to use the default (2), or pass a numeric value: `expect.closeTo(1.0, 3)`.","Coerce config-derived precision: `Number(precision)` and validate it is a finite integer.","Double-check argument order: closeTo(expectedNumber, precisionNumber)."],"exampleFix":"// before\nexpect(result).toEqual(expect.closeTo(1.0, '3')); // precision as string\n\n// after\nexpect(result).toEqual(expect.closeTo(1.0, 3));","handlingStrategy":"type-guard","validationCode":"function withPrecision(value, precision) {\n  if (precision !== undefined && (typeof precision !== 'number' || !Number.isFinite(precision))) {\n    throw new TypeError('precision must be a number');\n  }\n  return precision === undefined ? expect.closeTo(value) : expect.closeTo(value, precision);\n}","typeGuard":"function isOptionalFiniteNumber(v: unknown): v is number | undefined {\n  return v === undefined || (typeof v === 'number' && Number.isFinite(v));\n}","tryCatchPattern":null,"preventionTips":["Omit the precision argument to use the default of 2 when unsure.","Keep argument order straight: closeTo(expected, precision).","Coerce config-driven precision with Number() and validate it is finite."],"tags":["expect","asymmetric-matcher","typeerror","numeric"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}