{"record":{"id":"1ece664e807c28ad","repo":"awslabs/llrt","slug":"you-must-provide-a-promise-to-expect-when-using-resolves-not","errorCode":null,"errorMessage":"You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.","messagePattern":"You must provide a Promise to expect\\(\\) when using \\.resolves, not '(.+?)'\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"llrt_core/src/modules/js/@llrt/expect/jest-expect.ts","lineNumber":529,"sourceCode":"    }\n  );\n\n  def(\"toSatisfy\", function (matcher: Function, message?: string) {\n    return this.be.satisfy(matcher, message);\n  });\n\n  utils.addProperty(\n    chai.Assertion.prototype,\n    \"resolves\",\n    function __VITEST_RESOLVES__(this: any) {\n      const error = new Error(\"resolves\");\n      utils.flag(this, \"promise\", \"resolves\");\n      utils.flag(this, \"error\", error);\n      const test: any = utils.flag(this, \"vitest-test\");\n      const obj = utils.flag(this, \"object\");\n\n      if (typeof obj?.then !== \"function\")\n        throw new TypeError(\n          `You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`\n        );\n\n      const proxy: any = new Proxy(this, {\n        get: (target, key, receiver) => {\n          const result = Reflect.get(target, key, receiver);\n\n          if (typeof result !== \"function\")\n            return result instanceof chai.Assertion ? proxy : result;\n\n          return async (...args: any[]) => {\n            const promise = obj.then(\n              (value: any) => {\n                utils.flag(this, \"object\", value);\n                return result.call(this, ...args);\n              },\n              (err: any) => {\n                const _error = new AssertionError(","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/awslabs/llrt/blob/742fc00b82cbeaab1c1b76f0d706c302a5cbc306/llrt_core/src/modules/js/@llrt/expect/jest-expect.ts#L511-L547","documentation":"This TypeError is thrown inside JestChaiExpect when the `.resolves` modifier is used but the value given to expect() does not have a `then` function, i.e. is not a Promise. `.resolves` unwraps the promise before applying matchers, so a non-Promise would make unwrapping impossible. The check is `typeof obj?.then !== 'function'` on the flagged object.","triggerScenarios":"Calling expect(value).resolves.toEqual(...) where value is a plain value, undefined, null, or a non-thenable object instead of a Promise.","commonSituations":"Refactoring an async function to return a plain value (forgot to make it async), awaiting twice so the promise was already resolved before expect, or calling a sync helper that returns data instead of a promise.","solutions":["Remove a redundant await: use expect(promise).resolves.toEqual(x), not expect(await promise).resolves.toEqual(x).","Ensure the function under test actually returns a Promise (mark it async or return the promise).","If the value is not async, drop .resolves and assert on it directly with expect(value).toEqual(x)."],"exampleFix":"// before\nconst result = await fetchData();\nexpect(result).resolves.toEqual({ ok: true }); // result is not a Promise\n// after\nexpect(fetchData()).resolves.toEqual({ ok: true });","handlingStrategy":"type-guard","validationCode":"if (!promise || typeof promise.then !== 'function') throw new TypeError('.resolves requires a Promise');","typeGuard":"function isPromise(v) {\n  return v !== null && (typeof v === 'object' || typeof v === 'function') && typeof v.then === 'function';\n}","tryCatchPattern":null,"preventionTips":["Never await before using .resolves; pass the promise itself.","Confirm the function under test is async/returns a promise.","Use .resolves only on call results, not stored awaited values."],"tags":["expect","promise","testing","type-mismatch"],"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"}