Skip to content

fix!: fail expect.poll when function didn't resolve in time#10233

Merged
sheremet-va merged 13 commits into
vitest-dev:mainfrom
hi-ogawa:fix-fail-expect-poll-when-function-didn-t-resolve-in-time
May 7, 2026
Merged

fix!: fail expect.poll when function didn't resolve in time#10233
sheremet-va merged 13 commits into
vitest-dev:mainfrom
hi-ogawa:fix-fail-expect-poll-when-function-didn-t-resolve-in-time

Conversation

@hi-ogawa

@hi-ogawa hi-ogawa commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR makes expect.poll respect timeout properly. 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 generic expect.poll.

This also updates expect.element, which relied on the old timeout behavior. Instead of switching between query and element with magic flag _isLastPollAttempt, it now resolves locators through locator.findElement. toMatchScreenshot still needs special handling but slightly simplified by moving the escape hatch explicitly on expect.poll side.

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

  • docs

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify

netlify Bot commented Apr 30, 2026

Copy link
Copy Markdown

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e825a30
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69f9f7d47fd74c00083ed0a5
😎 Deploy Preview https://deploy-preview-10233--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa added this to the 5.0.0 milestone Apr 30, 2026
Co-authored-by: Codex <noreply@openai.com>
@hi-ogawa hi-ogawa marked this pull request as ready for review April 30, 2026 06:53
@hi-ogawa hi-ogawa requested a review from Copilot May 2, 2026 02:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.poll to race callback/assertion execution against a timeout and expose an AbortSignal to poll callbacks.
  • Updates browser expect.element to resolve locators via findElement() 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.

Comment thread packages/vitest/src/integrations/chai/poll.ts
Comment thread packages/vitest/src/integrations/chai/poll.ts
Comment thread packages/browser/src/client/tester/expect-element.ts
Comment thread packages/browser/src/client/tester/expect-element.ts
@sheremet-va sheremet-va merged commit 4df048c into vitest-dev:main May 7, 2026
15 of 17 checks passed
@hi-ogawa hi-ogawa deleted the fix-fail-expect-poll-when-function-didn-t-resolve-in-time branch May 7, 2026 23:06
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expect.poll(.., { timeout }) doesn't fail early on given timeout

3 participants