awslabs/llrt · error · TypeError
You must provide a Promise to expect() when using…
Error message
You must provide a Promise to expect() when using .resolves, not '${typeof obj}'. What it means
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.
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).
Example fix
// before
const result = await fetchData();
expect(result).resolves.toEqual({ ok: true }); // result is not a Promise
// after
expect(fetchData()).resolves.toEqual({ ok: true }); Defensive patterns
Strategy: type-guard
Validate before calling
if (!promise || typeof promise.then !== 'function') throw new TypeError('.resolves requires a Promise'); Type guard
function isPromise(v) {
return v !== null && (typeof v === 'object' || typeof v === 'function') && typeof v.then === 'function';
} Prevention
- 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.
When it happens
Trigger: Calling expect(value).resolves.toEqual(...) where value is a plain value, undefined, null, or a non-thenable object instead of a Promise.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- You must provide a Promise to expect() when using .rejects…
- value must be , received
- You must provide an object to
- You must provide an array to
- "toThrow" expects string, RegExp, function, Error instance…
AI-assisted analysis of awslabs/llrt@742fc00b82 (2026-09-12).
Data as JSON: /api/errors/1ece664e807c28ad.
Report an issue: GitHub.
Appendix: source
Thrown at llrt_core/src/modules/js/@llrt/expect/jest-expect.ts:529
}
);
def("toSatisfy", function (matcher: Function, message?: string) {
return this.be.satisfy(matcher, message);
});
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: any = utils.flag(this, "vitest-test");
const obj = utils.flag(this, "object");
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 async (...args: any[]) => {
const promise = obj.then(
(value: any) => {
utils.flag(this, "object", value);
return result.call(this, ...args);
},
(err: any) => {
const _error = new AssertionError(View on GitHub (pinned to 742fc00b82)