Skip to content

Event listeners not working in custom elements #17531

@jrtcppv

Description

@jrtcppv

Current behavior

An event emitted from an element inside of the shadow DOM does not trigger an event listener in a parent custom element. The DOM in my example is as follows:

  • page-element (a custom element)
    • text-input (another custom element)
      • input
    • input

The page-element has an event listener on the text-input for an input event which removes the disabled attribute from the input element in the shadow DOM of the page-element. When tested in Cypress, the disabled attribute is never removed, however strangely if I run the test with cypress open and type in the input field myself after the test completes, the disabled attribute is removed instantly. I put in a 10 second wait after visit to make sure all the components are loaded and connected. Result in my example below is as follows:

  Test event listeners
    1) makes sure event listener works


  0 passing (15s)
  1 failing

  1) Test event listeners
       makes sure event listener works:
     AssertionError: Timed out retrying after 4000ms: expected '[ <input>, 1 more... ]' not to have attribute 'disabled'
      at Context.eval (http://localhost:63324/__cypress/tests?p=cypress\integration\spec.js:103:25)

Desired behavior

The test should cause the disabled attribute in the input element with type=submit to be removed.

Test code to reproduce

Clone this fork:

https://github.com/jrtcppv/cypress-test-tiny

Run the following:

npm install cypress
./node_modules/bin/cypress run

Cypress Version

7.7.0, 8.0.0, 8.1.0

Other

Really want Cypress to work for us, but our application has a ton of nested custom elements like this... hopefully this example will give us some insight into what the problem is. I'm also a Cypress noob so possible I am just doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions