{"record":{"id":"f845403b93357c70","repo":"vitest-dev/vitest","slug":"you-must-provide-a-promise-to-expect-when-using","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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jest-expect.ts","lineNumber":1091,"sourceCode":"\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: Test = utils.flag(this, 'vitest-test')\n      const obj = utils.flag(this, 'object')\n\n      if (utils.flag(this, 'poll')) {\n        throw new SyntaxError(\n          `expect.poll() is not supported in combination with .resolves`,\n        )\n      }\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\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\n          return (...args: any[]) => {\n            utils.flag(this, '_name', key)\n            const promise = Promise.resolve(obj).then(\n              (value: any) => {\n                utils.flag(this, 'object', value)\n                return result.call(this, ...args)","sourceCodeStart":1073,"sourceCodeEnd":1109,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-expect.ts#L1073-L1109","documentation":"`.resolves` requires a thenable as the subject of `expect()`. If `obj.then` is not a function (including when `obj` is null/undefined or a plain value), the matcher cannot await it and throws a `TypeError`. This guards the async machinery before constructing the proxy.","triggerScenarios":"`expect(42).resolves.toBe(42)`, `expect(null).resolves...`, or passing a value from a function that returned synchronously instead of a Promise.","commonSituations":"Forgetting `await`/`return` so the actual subject is the resolved value, not the promise; calling `.resolves` on a number, string, or object; a function that returns a value rather than a promise in the non-async code path.","solutions":["Return a Promise from the subject under test, or remove `.resolves` if the value is not a promise.","Add `async` to the producer so it consistently returns a Promise.","Use `await` correctly so you pass the promise itself to `expect()`."],"exampleFix":"// before\nexpect(getValue()).resolves.toBe(42) // getValue returns 42 synchronously\n\n// after\nexpect(getValue()).toBe(42)","handlingStrategy":"type-guard","validationCode":"const isThenable = (v: unknown): v is PromiseLike<unknown> =>\n  !!v && typeof (v as any).then === 'function'\nif (!isThenable(value)) { throw new Error('pass a Promise when using .resolves') }","typeGuard":"const isPromise = (v: unknown): v is Promise<unknown> =>\n  !!v && typeof (v as any).then === 'function'","tryCatchPattern":null,"preventionTips":["Make the producer consistently async so it returns a Promise.","Pass the promise itself, not its resolved value, to expect().","Remove .resolves when the subject is not a promise."],"tags":["expect","resolves","promise","type-error","jest-expect"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}