vitest-dev/vitest · error · SyntaxError

expect.poll() is not supported in combination with .rejects

Error message

expect.poll() is not supported in combination with .rejects

What it means

`.rejects` flags the assertion to expect a rejected promise. Vitest disallows pairing it with `expect.poll()` because poll already controls retry timing; chaining them is a `SyntaxError`. Thrown before any promise is inspected.

Source

Thrown at packages/expect/src/jest-expect.ts:1158

      })

      return proxy
    },
  )

  utils.addProperty(
    chai.Assertion.prototype,
    'rejects',
    function __VITEST_REJECTS__(this: any) {
      const error = new Error('rejects')
      utils.flag(this, 'promise', 'rejects')
      utils.flag(this, 'error', error)
      const test: Test = utils.flag(this, 'vitest-test')
      const obj = utils.flag(this, 'object')
      const wrapper = typeof obj === 'function' ? obj() : obj // for jest compat

      if (utils.flag(this, 'poll')) {
        throw new SyntaxError(
          `expect.poll() is not supported in combination with .rejects`,
        )
      }

      if (typeof wrapper?.then !== 'function') {
        throw new TypeError(
          `You must provide a Promise to expect() when using .rejects, not '${typeof wrapper}'.`,
        )
      }

      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
          }

View on GitHub (pinned to 1fa9837ec2)

Solutions

  1. Use `expect.poll(() => p).toThrow()` after letting the poll callback return the awaited rejection, or
  2. Use `expect(p).rejects.toThrow()` without `poll` for a straightforward rejection assertion.

Example fix

// before
expect.poll(() => failingCall()).rejects.toThrow('boom')

// after
expect(failingCall()).rejects.toThrow('boom')
Defensive patterns

Strategy: validation

Validate before calling

// never combine .rejects with expect.poll
// use expect(p).rejects.toThrow() or poll on a sync value

Prevention

When it happens

Trigger: `expect.poll(() => p).rejects.toThrow()` or any `.rejects` access on an assertion flagged with `poll`.

Common situations: Refactoring a `.rejects` test to use `expect.poll` without removing `.rejects`; copying a rejection pattern into a poll loop.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/c09f3d593d1c6a09. Report an issue: GitHub.