Skip to content

fix(test): Fix flaky MetricsTabContent sidebar toggle test#111843

Draft
JoshuaKGoldberg wants to merge 1 commit intomasterfrom
fix/flaky-metrics-tab-spec
Draft

fix(test): Fix flaky MetricsTabContent sidebar toggle test#111843
JoshuaKGoldberg wants to merge 1 commit intomasterfrom
fix/flaky-metrics-tab-spec

Conversation

@JoshuaKGoldberg
Copy link
Copy Markdown
Member

Summary

Fixes a flaky test: MetricsTabContent (tracemetrics-ui-refresh) › toggles the query builder sidebar with the expand control

Root cause: When the sidebar is expanded, the SearchQueryBuilderCombobox inside the MetricToolbar mounts and begins async initialization (attribute key fetching via React Query). The test only waited for the toolbar's data-test-id to appear but not for the SearchQueryBuilderCombobox to finish mounting. When the test ended, pending async state updates completed outside of act(), triggering a console.error that jest-fail-on-console caught.

Fix: After expanding the sidebar and confirming the toolbar is present, add a findByRole('combobox') assertion to wait for the SearchQueryBuilderCombobox to fully initialize. This ensures all async state updates from the component's mount cycle are flushed within the test's act() boundary before cleanup runs.

Test plan

  • Test passes consistently (verified 5 consecutive runs)
  • All other tests in the file continue to pass
  • Pre-commit hooks pass

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