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
- Use `expect.poll(() => p).toThrow()` after letting the poll callback return the awaited rejection, or
- 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
- Do not chain .rejects onto expect.poll.
- Use plain expect(p).rejects.toThrow() for rejection assertions.
- Review poll-based tests to ensure no leftover .rejects modifier.
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
- expect.poll() is not supported in combination with .resolves
- You must provide a Promise to expect() when using .rejects,
- .toHaveProperty() expects to receive a valid object, but got
- ${utils.inspect(assertion._obj)} is not a spy or a call to a
- ${utils.inspect(resultSpy)} is not a spy or a call to a spy
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/c09f3d593d1c6a09.
Report an issue: GitHub.