cypress-shadow-dom icon indicating copy to clipboard operation
cypress-shadow-dom copied to clipboard

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

Open DesignByOnyx opened this issue 4 years ago • 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.

DesignByOnyx avatar Dec 27 '19 22:12 DesignByOnyx