{"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":1086,"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":1068,"sourceCodeEnd":1104,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/expect/src/jest-expect.ts#L1068-L1104","documentation":"TypeError thrown by the 'resolves' property getter when the value passed to expect() is not thenable (has no .then function). .resolves only makes sense for real Promise-like values; anything else is a programming error detected before any assertion runs.","triggerScenarios":"expect(42).resolves.toBe(42); expect('foo').resolves; expect(undefined).resolves; expect({}).resolves. Triggered when typeof obj?.then !== 'function' at line 1085.","commonSituations":"The developer omitted await or forgot to call the async function: expect(getValue()).resolves where getValue returns a plain value; or asserting .resolves on a synchronous return.","solutions":["Ensure expect() receives a real promise: expect(asyncFn()).resolves or expect(promise).resolves.","If the value is synchronous, remove .resolves: expect(value).toBe(x).","Add the missing await/call so a promise is actually produced."],"exampleFix":"// before\nexpect(getCount()).resolves.toBe(5); // getCount is sync\n// after\nexpect(getCount()).toBe(5);","handlingStrategy":"type-guard","validationCode":"if (typeof (obj as any)?.then !== 'function') throw new TypeError(`expect() target is ${typeof obj}, not a Promise — drop .resolves`);","typeGuard":"const isThenable = (v: unknown): v is PromiseLike<unknown> =>\n  v != null && typeof (v as any).then === 'function';","tryCatchPattern":null,"preventionTips":["Only chain .resolves when expect() receives a real Promise.","For sync values, assert directly without .resolves."],"tags":["typeerror","resolves","promise","type-mismatch","async"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}