{"record":{"id":"e6248eef8af86515","repo":"vitest-dev/vitest","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/jest-asymmetric-matchers.ts","lineNumber":350,"sourceCode":"  toString() {\n    return `String${this.inverse ? 'Not' : ''}Matching`\n  }\n\n  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: number) {\n    if (!isA('Number', other)) {\n      return false\n    }\n\n    let result = false\n    if (\n      other === Number.POSITIVE_INFINITY\n      && this.sample === Number.POSITIVE_INFINITY\n    ) {\n      result = true // Infinity - Infinity is NaN","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-asymmetric-matchers.ts#L332-L368","documentation":"CloseTo's second argument (precision, default 2) must also be a Number; isA('Number', precision) guards it independently of the sample. A non-numeric precision throws even when the sample is valid.","triggerScenarios":"expect.closeTo(sample, precision) where precision is a string, null, object, or NaN (e.g. expect.closeTo(1.5, '2')).","commonSituations":"Passing precision read from a config/env as a string; passing undefined explicitly (default applies, so usually fine); passing a float precision where an integer was expected.","solutions":["Pass an integer number for precision: expect.closeTo(1.5, 2).","Coerce with Number(...) and Math.round for config-sourced precision.","Omit precision to accept the default of 2."],"exampleFix":"// before\nexpect(value).toEqual(expect.closeTo(1.5, '2'))\n// after\nexpect(value).toEqual(expect.closeTo(1.5, 2))","handlingStrategy":"type-guard","validationCode":"function asCloseTo(sample, precision = 2) {\n  if (typeof precision !== 'number' || Number.isNaN(precision)) {\n    throw new TypeError('expect.closeTo precision must be a Number')\n  }\n  return expect.closeTo(sample, precision)\n}","typeGuard":"function isIntegerNumber(v): v is number {\n  return typeof v === 'number' && Number.isInteger(v)\n}","tryCatchPattern":null,"preventionTips":["Pass an integer number for precision (or omit it for the default 2).","Round config-sourced precision with Math.round(Number(p)).","Keep precision and sample arguments in the right order."],"tags":["expect","asymmetric-matcher","type-error"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}