From 70af6f1dd19b1bed67463b00ea35c90f1e422b11 Mon Sep 17 00:00:00 2001 From: Kevin Groat Date: Sun, 2 Apr 2023 09:51:32 -0400 Subject: [PATCH] fix: make clicks on type('{enter}') composed --- .../e2e/commands/actions/type_events_spec.js | 13 +++++++++++++ packages/driver/src/cy/commands/actions/type.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/driver/cypress/e2e/commands/actions/type_events_spec.js b/packages/driver/cypress/e2e/commands/actions/type_events_spec.js index efa72c7e3ce5..d4a0ad9b294e 100644 --- a/packages/driver/cypress/e2e/commands/actions/type_events_spec.js +++ b/packages/driver/cypress/e2e/commands/actions/type_events_spec.js @@ -649,6 +649,19 @@ describe('src/cy/commands/actions/type - #type events', () => { }) }) }) + + describe('shadow dom', () => { + // https://github.com/cypress-io/cypress/issues/26392 + it('propagates through shadow roots', () => { + cy.visit('fixtures/shadow-dom-button.html') + + cy.get('cy-test-element').invoke('on', 'click', cy.spy().as('clickSpy')) + + cy.get('cy-test-element').shadow().find('button').focus().type('{enter}') + + cy.get('@clickSpy').should('have.been.called') + }) + }) }) describe(`type(' ') fires click event on button-like elements`, () => { diff --git a/packages/driver/src/cy/commands/actions/type.ts b/packages/driver/src/cy/commands/actions/type.ts index a8fb90851c55..bdecb07e6bca 100644 --- a/packages/driver/src/cy/commands/actions/type.ts +++ b/packages/driver/src/cy/commands/actions/type.ts @@ -294,7 +294,7 @@ export default function (Commands, Cypress, cy, state, config) { const fireClickEvent = (el) => { const ctor = $dom.getDocumentFromElement(el).defaultView!.PointerEvent - const event = new ctor('click') + const event = new ctor('click', { composed: true }) el.dispatchEvent(event) }