fix!: fail expect.poll when function didn't resolve in time#10233
Merged
sheremet-va merged 13 commits intoMay 7, 2026
Merged
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: Codex <noreply@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens expect.poll timeout behavior so pending poll callbacks and async assertions fail when the configured timeout expires, and it adapts browser-facing expect.element to that stricter model. In the Vitest codebase, this touches core polling, browser locator assertions, snapshot polling, tests, and user docs.
Changes:
- Reworks
expect.pollto race callback/assertion execution against a timeout and expose anAbortSignalto poll callbacks. - Updates browser
expect.elementto resolve locators viafindElement()instead of the old last-attempt flag flow. - Adds regression tests and documentation for the stricter timeout/abort behavior.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
test/unit/test/expect-poll.test.ts |
Replaces old last-attempt flag tests with timeout and abort-signal coverage for unresolved callbacks/assertions. |
test/snapshots/test/domain-poll.test.ts |
Adds snapshot-poll coverage for abort signaling on timeout. |
test/browser/test/findElement.test.ts |
Adds a browser regression test asserting expect.element now surfaces strict locator behavior. |
test/browser/test/expect-element.test.ts |
Removes the old test that depended on the previous query-vs-element last-attempt behavior. |
packages/vitest/src/types/global.ts |
Updates the public expect.poll callback type to receive { signal }. |
packages/vitest/src/integrations/chai/poll.ts |
Implements the new timeout race logic and timeout-specific poll errors. |
packages/snapshot/src/client.ts |
Threads abort signaling into domain snapshot polling timeouts. |
packages/browser/src/client/tester/expect-element.ts |
Switches expect.element locator resolution to findElement() with a shared deadline. |
packages/browser/matchers.d.ts |
Refreshes expect.element type/docs text to match the new behavior. |
package.json |
Changes the root test script target from test-core to test-unit. |
docs/api/expect.md |
Documents whole-operation timeout semantics and the new AbortSignal callback argument. |
docs/api/browser/assertions.md |
Updates the expect.element docs to describe locator resolution plus poll timeout behavior. |
Co-authored-by: Codex <noreply@openai.com>
sheremet-va
approved these changes
May 7, 2026
9 tasks
This was referenced May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
expect.poll(.., { timeout })doesn't fail early on giventimeout#9844pollrun to stop at timeout #9848 (supersedes)This PR makes
expect.pollrespecttimeoutproperly. If the poll callback or async assertion does not resolve in time, the assertion now fails instead of waiting indefinitely or accepting a late success. Domain snapshot polling already used this stricter model, so this ports the same approach back into genericexpect.poll.This also updates
expect.element, which relied on the old timeout behavior. Instead of switching betweenqueryandelementwith magic flag_isLastPollAttempt, it now resolves locators throughlocator.findElement.toMatchScreenshotstill needs special handling but slightly simplified by moving the escape hatch explicitly onexpect.pollside.This is a breaking change because the previous behavior was forgiving: slow callbacks, slow async matchers, and last-attempt-only successes could pass after the configured timeout. Those cases now fail.
TODO
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.