Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make clicks on type('{enter}') composed #26395

Merged
merged 11 commits into from
Apr 10, 2023
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _Released 04/11/2023 (PENDING)_
- Fixed an issue in the onboarding wizard where project framework & bundler would not be auto-detected when opening directly into component testing mode using the `--component` CLI flag. Fixes [#22777](https://github.com/cypress-io/cypress/issues/22777).
- Updated to use the `SEMAPHORE_GIT_WORKING_BRANCH` [Semphore](https://docs.semaphoreci.com) CI environment variable to correctly associate a Cloud run to the current branch. Previously this was incorrectly associating a run to the target branch. Fixes [#26309](https://github.com/cypress-io/cypress/issues/26309).
- Fix an edge case in Component Testing where a custom `baseUrl` in `tsconfig.json` for Next.js 13.2.0+ is not respected. This was partially fixed in [#26005](https://github.com/cypress-io/cypress/pull/26005), but an edge case was missed. Fixes [#25951](https://github.com/cypress-io/cypress/issues/25951).
- Fixed an issue where `click` events fired on `.type('{enter}')` did not propagate through shadow roots. Fixes [#26392](https://github.com/cypress-io/cypress/issues/26392).

**Misc:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ describe('src/cy/commands/actions/type - #type events', () => {
cy.get(':text:first').type('a')
})

it('receives textInput event', (done) => {
// TODO fix this test in Webkit https://github.com/cypress-io/cypress/issues/26438
it('receives textInput event', { browser: '!webkit' }, (done) => {
const $txt = cy.$$(':text:first')

$txt[0].addEventListener('textInput', (e) => {
Expand Down Expand Up @@ -593,7 +594,8 @@ describe('src/cy/commands/actions/type - #type events', () => {
]

targets.forEach((target) => {
it(target, () => {
// TODO fix this test in Webkit https://github.com/cypress-io/cypress/issues/26438
it(target, { browser: '!webkit' }, () => {
cy.get(`#target-${target}`).focus().type('{enter}')

cy.get('li').should('have.length', 4)
Expand All @@ -606,7 +608,8 @@ describe('src/cy/commands/actions/type - #type events', () => {

describe('keydown triggered on another element', () => {
targets.forEach((target) => {
it(target, () => {
// TODO fix this test in Webkit https://github.com/cypress-io/cypress/issues/26438
it(target, { browser: '!webkit' }, () => {
cy.get('#focus-options').select(target)
cy.get('#input-text').focus().type('{enter}')

Expand Down Expand Up @@ -649,6 +652,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`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/actions/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down