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

  1. Remove a redundant await: use expect(promise).resolves.toEqual(x), not expect(await promise).resolves.toEqual(x).
  2. Ensure the function under test actually returns a Promise (mark it async or return the promise).
  3. 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

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


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)