Skip to content

Commit 04d087a

Browse files
committed
fix
1 parent e4f5b10 commit 04d087a

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Shadow DOM Button test</title>
5+
</head>
6+
7+
<body>
8+
<cy-test-element id='element'>Click me!</cy-test-element>
9+
<script>
10+
class CyTestElement extends HTMLElement {
11+
constructor() {
12+
super();
13+
14+
this.attachShadow({ mode: 'open' });
15+
const button = document.createElement('button');
16+
const slot = document.createElement('slot');
17+
18+
button.setAttribute('data-test-id', 'my-button')
19+
20+
button.appendChild(slot);
21+
22+
button.addEventListener('click', () => {
23+
const div = document.createElement('div');
24+
div.textContent = 'Clicked'
25+
26+
this.shadowRoot.appendChild(div);
27+
});
28+
29+
this.shadowRoot.appendChild(
30+
button
31+
);
32+
}
33+
}
34+
35+
customElements.define('cy-test-element', CyTestElement);
36+
</script>
37+
</body>
38+
</html>

packages/driver/cypress/integration/commands/actions/click_spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3985,6 +3985,13 @@ describe('shadow dom', () => {
39853985

39863986
cy.get('#shadow-element-1').click()
39873987
})
3988+
3989+
// https://github.com/cypress-io/cypress/issues/18008
3990+
it('ignores the covering shadow host', () => {
3991+
cy.visit('/fixtures/shadow-dom-button.html')
3992+
3993+
cy.get('#element').shadow().find('[data-test-id="my-button"]').click()
3994+
})
39883995
})
39893996

39903997
describe('mouse state', () => {

packages/driver/src/cy/ensures.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,20 @@ export const create = (state, expect) => {
328328
const cmd = state('current').get('name')
329329

330330
if (!$dom.isDescendent($el1, $el2)) {
331+
// https://github.com/cypress-io/cypress/issues/18008
332+
// when an element inside a shadow root is covered by its shadow host
333+
if (
334+
$dom.isWithinShadowRoot($el1.get(0)) &&
335+
$el1.get(0).getRootNode() === $el2.get(0).shadowRoot
336+
) {
337+
return
338+
}
339+
331340
if ($el2) {
332341
const element1 = $dom.stringify($el1)
333342
const element2 = $dom.stringify($el2)
334343

335-
$errUtils.throwErrByPath('dom.covered', {
344+
return $errUtils.throwErrByPath('dom.covered', {
336345
onFail,
337346
args: { cmd, element1, element2 },
338347
errProps: {

0 commit comments

Comments
 (0)