Skip to content

[Fix] Jest Tests.x-pack/solutions/observability/plugins/exploratory_view/public/components/shared/exploratory_view/components - FilterLabel should render properly#262207

Merged
ana-davydova merged 2 commits intoelastic:mainfrom
ana-davydova:fix-skipped-test-filterLabel
Apr 9, 2026

Conversation

@ana-davydova
Copy link
Copy Markdown
Contributor

@ana-davydova ana-davydova commented Apr 9, 2026

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.

…iew/public/components/shared/exploratory_view/components - FilterLabel should render properly
@ana-davydova ana-davydova requested a review from a team as a code owner April 9, 2026 09:33
@github-actions github-actions Bot added the author:actionable-obs PRs authored by the actionable obs team label Apr 9, 2026
@ana-davydova ana-davydova added release_note:skip Skip the PR/issue when compiling release notes backport:version Backport to applied version labels v9.4.0 v9.3.1 labels Apr 9, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 9, 2026

Approvability

Verdict: 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.

@fkanout fkanout removed the v9.3.1 label Apr 9, 2026
);

await waitFor(async () => {
expect(await screen.findByText('elastic-co')).toBeInTheDocument();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ana-davydova, so the only issue that we had this elastic-co twice?

Copy link
Copy Markdown
Contributor Author

@ana-davydova ana-davydova Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fkanout fkanout added the v9.3.1 label Apr 9, 2026
@ana-davydova ana-davydova added v9.3.0 and removed v9.3.1 labels Apr 9, 2026
@ana-davydova ana-davydova enabled auto-merge (squash) April 9, 2026 10:02
@ana-davydova ana-davydova merged commit 6431ca5 into elastic:main Apr 9, 2026
23 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 9.3

https://github.com/elastic/kibana/actions/runs/24186390126

@ana-davydova ana-davydova deleted the fix-skipped-test-filterLabel branch April 9, 2026 10:55
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 9, 2026
…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)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.3

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 9, 2026
…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>
ana-davydova added a commit that referenced this pull request Apr 27, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:actionable-obs PRs authored by the actionable obs team backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes v9.3.0 v9.3.4 v9.4.0

Projects

None yet

3 participants