{"record":{"id":"f944ce2f2e759671","repo":"vitest-dev/vitest","slug":"expected-is-not-a-number","errorCode":null,"errorMessage":"Expected is not a Number","messagePattern":"Expected is not a Number","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jest-asymmetric-matchers.ts","lineNumber":346,"sourceCode":"\n    return this.inverse ? !result : result\n  }\n\n  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 (","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-asymmetric-matchers.ts#L328-L364","documentation":"The CloseTo asymmetric matcher (expect.closeTo) requires its sample to be a Number; isA('Number', sample) rejects NaN and non-numbers. It is used for approximate floating-point equality within a precision.","triggerScenarios":"expect.closeTo(sample) where sample is a string, null, object, or NaN.","commonSituations":"Passing a numeric string ('1.5') instead of a number; passing null from an optional field; passing a BigInt (not a Number).","solutions":["Pass a real number: expect.closeTo(1.5, 2).","Coerce validated numeric strings with Number(...) and confirm !Number.isNaN.","For BigInt values, convert explicitly or use a different matcher."],"exampleFix":"// before\nexpect(value).toEqual(expect.closeTo('1.50', 2))\n// after\nexpect(value).toEqual(expect.closeTo(1.5, 2))","handlingStrategy":"type-guard","validationCode":"function asCloseTo(sample, precision = 2) {\n  if (typeof sample !== 'number' || Number.isNaN(sample)) {\n    throw new TypeError('expect.closeTo needs a Number sample')\n  }\n  return expect.closeTo(sample, precision)\n}","typeGuard":"function isFiniteNumber(v): v is number {\n  return typeof v === 'number' && !Number.isNaN(v)\n}","tryCatchPattern":null,"preventionTips":["Pass numeric literals to expect.closeTo.","Coerce validated numeric strings with Number() first.","Remember BigInt is not a Number — convert or pick another matcher."],"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"}