{"record":{"id":"f6faef0c0793d8dc","repo":"vitest-dev/vitest","slug":"expect-poll-is-not-supported-in-combination-with-f6faef","errorCode":null,"errorMessage":"expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.","messagePattern":"expect\\.poll\\(\\) is not supported in combination with \\.(.+?)\\(\\)\\. Use vi\\.waitFor\\(\\) if your assertion condition is unstable\\.","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/integrations/chai/poll.ts","lineNumber":82,"sourceCode":"    chai.util.flag(assertion, '_poll.interval', interval)\n    const test = chai.util.flag(assertion, 'vitest-test') as Test | undefined\n    if (!test) {\n      throw new Error('expect.poll() must be called inside a test')\n    }\n    const proxy: any = new Proxy(assertion, {\n      get(target, key, receiver) {\n        const assertionFunction = Reflect.get(target, key, receiver)\n\n        if (typeof assertionFunction !== 'function') {\n          return assertionFunction instanceof chai.Assertion ? proxy : assertionFunction\n        }\n\n        if (key === 'assert') {\n          return assertionFunction\n        }\n\n        if (typeof key === 'string' && unsupported.includes(key)) {\n          throw new SyntaxError(\n            `expect.poll() is not supported in combination with .${key}(). Use vi.waitFor() if your assertion condition is unstable.`,\n          )\n        }\n\n        // Core poll stack-trace trick:\n        //   1. capture STACK_TRACE_ERROR here before entering the async poll loop\n        //   2. when the matcher eventually fails, rethrow via throwWithCause()\n        //      so the final error keeps this earlier stack\n        //\n        // For example, when user writes:\n        //    await expect.poll(...).toBeSomething()\n        // STACK_TRACE_ERROR.stack would look like\n        //   at ...(more internal stacks)...\n        //   at __VITEST_POLL_CHAIN__ .../packages/vitest/dist/...\n        //   at .../my-file.test.ts:12:3   (this points to `toBeSomething()` callsite in user test file)\n        // Vitest later filters out internal stacks from `vitest/dist`, so the reported errors correctly\n        // points to the user callsite for poll assertion errors.\n        //","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/integrations/chai/poll.ts#L64-L100","documentation":"expect.poll() retries an assertion until it passes or times out. Certain matchers are incompatible with retry semantics: snapshot matchers (always succeed once the value doesn't throw) and throw matchers (the poll callback is called until it stops throwing, so testing for throws is meaningless). The `unsupported` list blocks these combinations with a SyntaxError and points to vi.waitFor as the alternative for unstable non-assertion conditions.","triggerScenarios":"Chaining .poll() with toMatchSnapshot, toMatchInlineSnapshot, matchSnapshot, toThrowErrorMatchingSnapshot, toThrowErrorMatchingInlineSnapshot, throws, Throw, throw, toThrow, or toThrowError. Any of these in `expect.poll(fn).X()` triggers the error.","commonSituations":"Trying to retry a snapshot assertion on an unstable value; attempting to poll until a function throws; copy-pasting an existing throw/snapshot assertion and adding .poll().","solutions":["For unstable snapshot conditions, use vi.waitFor(() => { expect(value).toMatchInlineSnapshot(...) }) instead.","For throw-based conditions, restructure to poll the state directly rather than asserting a throw.","Remove .poll() if the matcher doesn't need retry semantics."],"exampleFix":"// before — unsupported combination:\nawait expect.poll(() => getValue()).toThrow()\n\n// after — use vi.waitFor for unstable conditions:\nawait vi.waitFor(() => { expect(() => getValue()).toThrow() })","handlingStrategy":"validation","validationCode":"const UNSUPPORTED_WITH_POLL = [\n  'matchSnapshot','toMatchSnapshot','toMatchInlineSnapshot',\n  'toThrowErrorMatchingSnapshot','toThrowErrorMatchingInlineSnapshot',\n  'throws','Throw','throw','toThrow','toThrowError'\n]\nif (UNSUPPORTED_WITH_POLL.includes(matcherName)) {\n  // use vi.waitFor instead of expect.poll\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not combine .poll() with snapshot or throw matchers.","Use vi.waitFor for unstable conditions that involve snapshots or throws."],"tags":["expect","poll","matcher","snapshot","assertion"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}