Skip to content

fix(test): Fix flaky ResultsSearchQueryBuilder spec#111855

Draft
JoshuaKGoldberg wants to merge 1 commit intomasterfrom
fix/flaky-results-search-query-builder-spec-v2
Draft

fix(test): Fix flaky ResultsSearchQueryBuilder spec#111855
JoshuaKGoldberg wants to merge 1 commit intomasterfrom
fix/flaky-results-search-query-builder-spec-v2

Conversation

@JoshuaKGoldberg
Copy link
Copy Markdown
Member

Summary

Fix two flaky tests in resultsSearchQueryBuilder.spec.tsx that failed 5 times on master in the last 30 days.

  1. "does not show function tags in has: dropdown" timed out at 5000ms because userEvent.type started typing before async API responses (feature flags via useFetchOrganizationFeatureFlags, recent searches) had settled. Re-renders triggered by those responses mid-typing slowed each keystroke. Fixed by splitting into userEvent.clickfindByRole('listbox')userEvent.keyboard so initial renders complete before typing begins.

  2. "shows normal tags in the dropdown" failed with act() warnings from SearchQueryBuilderCombobox because pending state updates from API responses fired after test assertions completed, triggering React's act() warning which jest-fail-on-console caught as a failure. Fixed by adding await waitFor() at the end to flush pending React state updates before teardown.

Also added MockApiClient.clearMockResponses() in beforeEach to prevent mock leakage between tests.

Test plan

  • Tests pass locally (3 consecutive runs)
  • Pre-commit passes

Made with Cursor

Stabilize two flaky tests:

1. "does not show function tags in has: dropdown" — timed out at 5000ms
   because userEvent.type started typing before async API responses
   (feature flags, recent searches) had settled, causing re-renders
   mid-typing that slowed each keystroke. Split into click + findByRole
   (listbox) + keyboard to let initial renders complete before typing.

2. "shows normal tags in the dropdown" — act() warning from
   SearchQueryBuilderCombobox because pending state updates from API
   responses fired after test assertions completed. Add waitFor at end
   to flush pending React state updates before teardown.

Also add MockApiClient.clearMockResponses() in beforeEach to prevent
mock leakage between tests.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Made-with: Cursor
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant