Repository navigation
test(react): poll rendered text instead of fixed sleeps - #38
Merged
Merged
Conversation
Several component() tests waited a fixed `await sleep(10)` then asserted rendered DOM text in a single shot. Under CI load the fetch and render don't always finish in that window, so the assertion samples `Loading` and fails (the react vitest project has no retry configured). Replace the racy sites with the polling `expect.element(...).toHaveTextContent(...)` assertion already used elsewhere in the file, which retries until the DOM matches or the test times out. Left the stale-data and in-flight-state tests on their sleeps, since those assert that something did not change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pzuraq
approved these changes
Jun 8, 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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Several
component()tests incomponent.test.tsxwaited a fixedawait sleep(10)then asserted rendered DOM text in a single shot (expect(...element().textContent).toBe(x)). Under CI runner load the fetch and React re-render don't always finish within that window, so the assertion samplesLoadingand fails. Thereactvitest project (chromium browser mode) has noretryconfigured, so one slow render fails the run.This is the flake reported for
should deduplicate multiple components using same query(AssertionError: expected 'Loading' to be '5'), which passed on a clean re-run with no code change.Fix
Replace the racy sites with the polling assertion already used elsewhere in the file:
expect.element(...).toHaveTextContent(...)retries until the DOM matches or the test times out, instead of sampling once. This also removes the now-redundanttoBeInTheDocument()+sleepscaffolding.Notes
renderCount, so the counts are only read once the update has fully propagated.sleeps on purpose: the stale-data / no-rerender tests assert that data did not change, and the "keep previous value during refetch" test samples a transient in-flight state on the query object (not rendered output). Polling would mask those.toBeInTheDocument()+ hard-toBe()pairs whose testid only renders onceisReady(loading renders a no-testidLoading...); those already wait for data.Verification
All 99 react browser tests pass (21/21 in
component.test.tsx).🤖 Generated with Claude Code