{"record":{"id":"7ebb07abf1322e35","repo":"awslabs/llrt","slug":"name-value-must-be-types-join-or-received-receivedtype","errorCode":null,"errorMessage":"${name} value must be ${types.join(\" or \")}, received \"${receivedType}\"","messagePattern":"(.+?) value must be (.+?), received \"(.+?)\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"llrt_core/src/modules/js/@llrt/expect/jest-expect.ts","lineNumber":634,"sourceCode":"            return recordAsyncExpect(test, promise);\n          };\n        },\n      });\n\n      return proxy;\n    }\n  );\n};\n\nexport function assertTypes(\n  value: unknown,\n  name: string,\n  types: string[]\n): void {\n  const receivedType = typeof value;\n  const pass = types.includes(receivedType);\n  if (!pass)\n    throw new TypeError(\n      `${name} value must be ${types.join(\" or \")}, received \"${receivedType}\"`\n    );\n}\n\nexport function recordAsyncExpect(\n  test: any,\n  promise: Promise<any> | PromiseLike<any>\n) {\n  // record promise for test, that resolves before test ends\n  if (test && promise instanceof Promise) {\n    // if promise is explicitly awaited, remove it from the list\n    promise = promise.finally(() => {\n      const index = test.promises.indexOf(promise);\n      if (index !== -1) test.promises.splice(index, 1);\n    });\n\n    // record promise\n    if (!test.promises) test.promises = [];","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/awslabs/llrt/blob/742fc00b82cbeaab1c1b76f0d706c302a5cbc306/llrt_core/src/modules/js/@llrt/expect/jest-expect.ts#L616-L652","documentation":"This TypeError is thrown by the `assertTypes` helper in @llrt/expect, used by matchers to validate that the expectation value has one of the allowed JavaScript types. It computes `typeof value` and compares against the accepted type list; on mismatch it reports the expected types joined by 'or' and the actual received type. JestChaiExpect matchers call it before performing comparisons.","triggerScenarios":"Calling a matcher that internally asserts types, e.g. expect(x).toBeCloseTo(nonNumber) or expect(x).toMatchObject(nonObject) — any call where the runtime typeof of the value is not in the matcher's allowed types array.","commonSituations":"Passing null/undefined where a primitive is expected, passing a string number ('1.5') to toBeCloseTo, or refactors that changed a value's type without updating the test.","solutions":["Convert the value to the expected type before asserting (Number('1.5'), etc.).","Check the value with typeof / an if-guard before the matcher call.","Fix the source of the value so it produces the intended type (often an API returned null)."],"exampleFix":"// before\nexpect(result.rate).toBeCloseTo(0.5); // result.rate is '0.5' (string)\n// after\nexpect(Number(result.rate)).toBeCloseTo(0.5);","handlingStrategy":"validation","validationCode":"if (typeof value !== 'number') throw new TypeError('toBeCloseTo expects a number, got ' + typeof value);","typeGuard":"function isType(v, ...types) {\n  return types.includes(typeof v);\n}","tryCatchPattern":null,"preventionTips":["Coerce values at the boundary (Number(), String()) before asserting.","Check for null/undefined from API responses before matching.","Update tests when the shape of returned data changes."],"tags":["expect","type-mismatch","testing"],"backgroundTag":"type-mismatch","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"}