{"record":{"id":"36268a9a4afb069d","repo":"awslabs/llrt","slug":"expected-is-not-a-number","errorCode":null,"errorMessage":"Expected is not a Number","messagePattern":"Expected is not a Number","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"llrt_core/src/modules/js/@llrt/expect/jest-asymmetric-matchers.ts","lineNumber":301,"sourceCode":"    const result = isA(\"String\", other) && this.sample.test(other);\n\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)) throw new Error(\"Expected is not a Number\");\n\n    if (!isA(\"Number\", precision)) throw new Error(\"Precision is not a Number\");\n\n    super(sample);\n    this.inverse = inverse;\n    this.precision = precision;\n  }\n\n  asymmetricMatch(other: number) {\n    if (!isA(\"Number\", other)) return false;\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\n    } else if (","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/awslabs/llrt/blob/742fc00b82cbeaab1c1b76f0d706c302a5cbc306/llrt_core/src/modules/js/@llrt/expect/jest-asymmetric-matchers.ts#L283-L319","documentation":"CloseTo compares numbers with a decimal precision, so both its sample and precision must be numbers. The constructor throws this plain Error when the sample is not a number, before any comparison can happen.","triggerScenarios":"expect.closeTo('1.5'), expect.closeTo(null), expect.closeTo(undefined), or expect.not.closeTo with a non-number sample.","commonSituations":"Passing numeric strings parsed from JSON/config that were never converted, or NaN-producing variables, or mixing up argument order so a precision lands in the sample slot.","solutions":["Convert with Number(value) or parseFloat(value) before passing.","Use expect.toBeCloseTo(n, digits) on the value itself instead of the asymmetric matcher.","Fix the data source so the value is a real number.","Ensure argument order: expect.closeTo(sample, precision) with both numeric."],"exampleFix":"// before\nexpect(val).toEqual(expect.closeTo('3.14'));\n// after\nexpect(val).toEqual(expect.closeTo(Number('3.14')));","handlingStrategy":"validation","validationCode":"if (typeof sample !== 'number' || Number.isNaN(sample)) throw new TypeError('closeTo sample must be a finite number');","typeGuard":"const isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);","tryCatchPattern":"try { expect(v).toEqual(expect.closeTo(n)); } catch (e) { /* n was not a number */ }","preventionTips":["Coerce numeric strings with Number()/parseFloat before use","Prefer toBeCloseTo on the value directly","Keep sample and precision argument order straight","Type numeric test fixtures as number"],"tags":["testing","validation","numbers","asymmetric-matcher"],"backgroundTag":"invalid-argument-value","analyzedSha":"742fc00b82cbeaab1c1b76f0d706c302a5cbc306","analyzedAt":"2026-09-12T11:14:07.838Z","contentChangedAt":"2026-09-12T11:14:07.838Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}