[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly#262207
Conversation
…iew/public/components/shared/exploratory_view/components - FilterLabel should render properly
ApprovabilityVerdict: Would Approve Test-only changes that re-enable a previously flaky test with improved async handling patterns. No runtime code is affected. The author is the designated code owner of the changed file. Macroscope would have approved this PR. A repo admin can enable approvability here. |
| ); | ||
|
|
||
| await waitFor(async () => { | ||
| expect(await screen.findByText('elastic-co')).toBeInTheDocument(); |
There was a problem hiding this comment.
@ana-davydova, so the only issue that we had this elastic-co twice?
There was a problem hiding this comment.
Looks like the duplicate was a smaller issue.
But the major problem was nested async findByText (that retries on its own) inside waitFor (also retries). This created two independent retry loops fighting each other. When findByText resolves an element reference, the component can re-render between that moment and when toBeInTheDocument() checks it, making the reference stale → timeout.
The fix I used is waitFor with synchronous getByText instead — all should run atomically in a single retry cycle, without timeout error.
|
Starting backport for target branches: 9.3 https://github.com/elastic/kibana/actions/runs/24186390126 |
…iew/public/components/shared/exploratory_view/components - FilterLabel should render properly (elastic#262207) Resolves elastic#253320 **Root cause:** Anti-pattern of nesting findByText (async, retries) inside waitFor (also retries). The FilterItem component re-renders due to injectI18n() being called inside the render function, which makes element references go stale between the findByText resolution and the toBeInTheDocument() check. **Fix:** Replaced with waitFor(() => { getByText... }) — synchronous assertions inside waitFor so all checks run atomically in one retry cycle. Removed the duplicate assertion and unskipped the test. Verified: 155/155 consecutive runs pass locally. (cherry picked from commit 6431ca5)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…tory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly (#262207) (#262237) # Backport This will backport the following commits from `main` to `9.3`: - [[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly (#262207)](#262207) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Anna Davydova","email":"ana.davydova@elastic.co"},"sourceCommit":{"committedDate":"2026-04-09T10:53:23Z","message":"[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly (#262207)\n\nResolves #253320 \n\n**Root cause:** Anti-pattern of nesting findByText (async, retries)\ninside waitFor (also retries). The FilterItem component re-renders due\nto injectI18n() being called inside the render function, which makes\nelement references go stale between the findByText resolution and the\ntoBeInTheDocument() check.\n\n**Fix:** Replaced with waitFor(() => { getByText... }) — synchronous\nassertions inside waitFor so all checks run atomically in one retry\ncycle. Removed the duplicate assertion and unskipped the test.\n\nVerified: 155/155 consecutive runs pass locally.","sha":"6431ca5e8766e8de8121d08a52ec09b4ead935cc","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.3.0","v9.4.0","author:actionable-obs"],"title":"[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly","number":262207,"url":"https://github.com/elastic/kibana/pull/262207","mergeCommit":{"message":"[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly (#262207)\n\nResolves #253320 \n\n**Root cause:** Anti-pattern of nesting findByText (async, retries)\ninside waitFor (also retries). The FilterItem component re-renders due\nto injectI18n() being called inside the render function, which makes\nelement references go stale between the findByText resolution and the\ntoBeInTheDocument() check.\n\n**Fix:** Replaced with waitFor(() => { getByText... }) — synchronous\nassertions inside waitFor so all checks run atomically in one retry\ncycle. Removed the duplicate assertion and unskipped the test.\n\nVerified: 155/155 consecutive runs pass locally.","sha":"6431ca5e8766e8de8121d08a52ec09b4ead935cc"}},"sourceBranch":"main","suggestedTargetBranches":["9.3"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/262207","number":262207,"mergeCommit":{"message":"[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly (#262207)\n\nResolves #253320 \n\n**Root cause:** Anti-pattern of nesting findByText (async, retries)\ninside waitFor (also retries). The FilterItem component re-renders due\nto injectI18n() being called inside the render function, which makes\nelement references go stale between the findByText resolution and the\ntoBeInTheDocument() check.\n\n**Fix:** Replaced with waitFor(() => { getByText... }) — synchronous\nassertions inside waitFor so all checks run atomically in one retry\ncycle. Removed the duplicate assertion and unskipped the test.\n\nVerified: 155/155 consecutive runs pass locally.","sha":"6431ca5e8766e8de8121d08a52ec09b4ead935cc"}}]}] BACKPORT--> Co-authored-by: Anna Davydova <ana.davydova@elastic.co>
Resolves #253320 This is a follow-up to #262207. ### Fix **Three changes to filter_label.test.tsx:** 1. `jest.setTimeout(10 * 1000)` → `jest.setTimeout(30 * 1000)` — gives enough headroom on stressed CI agents. 2. Replaced `waitFor(() => getByText(...))` with `await screen.findByText(...) `— copies the pattern used by the non-flaky `should display invert filter `sibling test. 3. Re-enabled the suite. **Verification** - [x] 155/155 consecutive local runs pass, 0 failures. Buildkite flaky-test-runner doesn't cover jest tests, so local runs are the only option. Made with Claude.
Resolves #253320
Root cause: Anti-pattern of nesting findByText (async, retries) inside waitFor (also retries). The FilterItem component re-renders due to injectI18n() being called inside the render function, which makes element references go stale between the findByText resolution and the toBeInTheDocument() check.
Fix: Replaced with waitFor(() => { getByText... }) — synchronous assertions inside waitFor so all checks run atomically in one retry cycle. Removed the duplicate assertion and unskipped the test.
Verified: 155/155 consecutive runs pass locally.