Skip to content

chore: chain cy.get assertions + clicks to avoid detached-DOM flakiness#97

Merged
jtroup merged 1 commit intostacklet/integrationfrom
elmo/sweet-moose
Mar 17, 2026
Merged

chore: chain cy.get assertions + clicks to avoid detached-DOM flakiness#97
jtroup merged 1 commit intostacklet/integrationfrom
elmo/sweet-moose

Conversation

@jtroup
Copy link

@jtroup jtroup commented Mar 14, 2026

what

Chain .should("be.visible").click() on a single cy.get() call
instead of issuing a separate cy.get() for the assertion and another
for the interaction. Two specs affected:

  • visualizations/table/table_spec.js.jvi-toggle expand clicks
  • user/logout_spec.jsLogOutButton click

why

When assertion and interaction use separate cy.get() calls, a React
re-render between the two commands can replace the DOM node. Cypress
then holds a stale reference and throws:

cy.click() failed because this element is detached from the DOM

Per https://on.cypress.io/element-has-detached-from-dom, the fix is to
re-query and interact in one chain so Cypress never holds a reference
across a potential re-render boundary. table_spec.js reproduced in CI
on 2026-03-14; logout_spec.js had the same latent pattern.

testing

Covered by the existing Cypress e2e suite. The table_spec.js failure
was observed in CI and no longer reproduces with this change.

docs

No docs needed.


🤖 Generated with Claude Code

Copy link

@ephan ephan left a comment

Choose a reason for hiding this comment

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

This is fine. It's odd to me doing a check and action in the same line. Usually we separate these for clarity although given the bug it looks like the only option.

I believe that the test would fail if the item was not visible when trying to click. So the should is probably unnecessary i.e.
cy.getByTestId("LogOutButton").click();
should behave the same as
cy.getByTestId("LogOutButton").should("be.visible").click();

@jtroup jtroup merged commit 3838ff1 into stacklet/integration Mar 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants