fix(tests): close radiogroup re-query race in fillRadio helper - #1312
Merged
Merged
Conversation
fillRadio/assertRadioValue waited for a radiogroup via waitFor(), then discarded that result and re-queried synchronously with getByRole. If the group briefly unmounted again between those two calls (e.g. a step re-entering a loading state from a second async fetch), the second call threw even though the first had just succeeded - the likely cause of the flaky ContractorOnboarding "Invite Contractor" test failure. Both helpers now keep the element waitFor() already resolved instead of re-querying. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
📦 Bundle Size Report
Size Limits
Largest Files (Top 5)
View All Files (450 total)
✅ Bundle size check passed |
Contributor
📊 Coverage Report⚪ Coverage unchanged
Detailed BreakdownLines Coverage
Statements Coverage
Functions Coverage
Branches Coverage
✅ Coverage check passed |
Contributor
|
Deploy preview for adp-cost-calculator ready!
Deployed with vercel-action |
Contributor
|
Deploy preview for remote-flows ready!
Deployed with vercel-action |
jordividaller
approved these changes
Sep 14, 2026
Merged
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.
Summary
ContractorOnboarding.test.tsx > should invite the contractor when the user clicks on the 'Invite Contractor' button, wherefillRadiofailed to find thePayment termsradiogroup even though the surroundingwaitForElementToBeRemoved(spinner)had already resolved.fillRadioandassertRadioValueinsrc/tests/testHelpers.tsxwaited for the radiogroup viawaitFor(() => screen.getByRole('radiogroup', ...)), then discarded that result and re-queried synchronously with a second, non-retryingscreen.getByRole(...)call. If the radiogroup briefly unmounted again between those two calls (e.g. a step re-entering a loading state from a second async fetch after the first resolves), the second call throws even though the first had just succeeded moments earlier — a genuine race window baked into the helper itself, not the test.waitFor()already resolved instead of re-querying it, closing the race window entirely. This affects every test in the suite that usesfillRadio/assertRadioValue(widely used across flows), not just the one that happened to be reported.Investigation notes
fillRadio(used in the failing test) andassertRadioValue(same pattern, same fix applied for consistency).waitFor()already returns whatever its callback returns, so capturing the resolved element removes the redundant, racy second query without changing any test's behavior.Test plan
npx vitest run— full suite passes (95 files / 958 tests)npm run type-check— cleannpm run lint— no new warnings (pre-existingexample/console warnings only)npm run check-format— clean🤖 Generated with Claude Code
Note
Low Risk
Test-only helper change with no production code impact; reduces flaky CI failures without altering intended test behavior.
Overview
Fixes a timing race in the shared test helpers
assertRadioValueandfillRadiointestHelpers.tsx.Both helpers used to call
waitForto find a radiogroup, then immediately run a second synchronousscreen.getByRole('radiogroup', …). If the group unmounted again between those steps (e.g. another loading pass), the second lookup could fail even thoughwaitForhad just succeeded. The change reuses the element returned fromwaitForand drops the redundant re-query, with a short comment explaining why.Behavior for callers is unchanged; the goal is fewer flaky failures in tests that interact with radiogroups (including contractor onboarding flows).
Reviewed by Cursor Bugbot for commit 0843f32. Bugbot is set up for automated code reviews on this repo. Configure here.