abramenal/cypress-shadow-dom

[Feature] - override $.contains to work with shadow trees

DesignByOnyx opened this issue · 0 comments

Current behavior:

There are still code paths which trigger Cypress' internal "ensureAttached" and friends which detects whether a DOM element is still attached to the DOM. For example, the following fails because Cypress thinks the input is detached:

cy.shadowGet('some-element')
  .shadowFind('input[type="checkbox"]')
  .shadowClick()
  .should('be.checked'); // error - input is detached from dom

Desired Behavior

Instead of reimplementing a shadow-friendly method across the entire Cypress API (especially should), we can extend the underlying utility methods to work with shadow trees. In this case, all code paths eventually call $.contains(doc, el) to determine whether or not the element is attached to the DOM. We can override the $.contains method to make it work with shadow structures by crawling up every "rootNode" until we reach the document.