vitest-dev/vitest · error · TypeError
You must provide a Promise to expect() when using .resolves,
Error message
You must provide a Promise to expect() when using .resolves, not '${typeof obj}'. What it means
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.
Source
Thrown at packages/expect/src/jest-expect.ts:1086
utils.addProperty(
chai.Assertion.prototype,
'resolves',
function __VITEST_RESOLVES__(this: any) {
const error = new Error('resolves')
utils.flag(this, 'promise', 'resolves')
utils.flag(this, 'error', error)
const test: Test = utils.flag(this, 'vitest-test')
const obj = utils.flag(this, 'object')
if (utils.flag(this, 'poll')) {
throw new SyntaxError(
`expect.poll() is not supported in combination with .resolves`,
)
}
if (typeof obj?.then !== 'function') {
throw new TypeError(
`You must provide a Promise to expect() when using .resolves, not '${typeof obj}'.`,
)
}
const proxy: any = new Proxy(this, {
get: (target, key, receiver) => {
const result = Reflect.get(target, key, receiver)
if (typeof result !== 'function') {
return result instanceof chai.Assertion ? proxy : result
}
return (...args: any[]) => {
utils.flag(this, '_name', key)
const promise = Promise.resolve(obj).then(
(value: any) => {
utils.flag(this, 'object', value)
return result.call(this, ...args)View on GitHub (pinned to d568f8ce37)
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.
Example fix
// before expect(getCount()).resolves.toBe(5); // getCount is sync // after expect(getCount()).toBe(5);
Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof (obj as any)?.then !== 'function') throw new TypeError(`expect() target is ${typeof obj}, not a Promise — drop .resolves`); Type guard
const isThenable = (v: unknown): v is PromiseLike<unknown> => v != null && typeof (v as any).then === 'function';
Prevention
- Only chain .resolves when expect() receives a real Promise.
- For sync values, assert directly without .resolves.
When it happens
Trigger: expect(42).resolves.toBe(42); expect('foo').resolves; expect(undefined).resolves; expect({}).resolves. Triggered when typeof obj?.then !== 'function' at line 1085.
Common situations: 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.
Related errors
- You must provide a Promise to expect() when using .rejects,
- expected promise to throw an error, but it didn't
- .toMatch() expects to receive a string, but got ${typeof act
- toContain() expected a DOM node as the argument, but got ${t
- ${utils.inspect(assertion._obj)} is not a spy or a call to a
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/f845403b93357c70.json.
Report an issue: GitHub.