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

Documentation and types do not reflect behaviour of then when returning element #14875

Closed
OliverJAsh opened this issue Feb 2, 2021 · 3 comments · Fixed by #15624
Closed

Documentation and types do not reflect behaviour of then when returning element #14875

OliverJAsh opened this issue Feb 2, 2021 · 3 comments · Fixed by #15624
Labels
type: typings Issue related to Cypress types (for TypeScript)

Comments

@OliverJAsh
Copy link
Contributor

Current behavior

Given

const event = new Event('click');

cy.get('div')
  .then((el$) => {
    const el: HTMLDivElement = el$[0];
    return el;
  })
  .then((el) => el.dispatchEvent(event));

This doesn't produce a TypeScript type error.

At runtime it throws an exception:

TypeError: el.dispatchEvent is not a function

This appears to happen because el is not actually a HTMLDivElement, despite what TypeScript thinks. It's actually a JQuery wrapped element.

Desired behavior

  • This should produce a type error at compile time (i.e. the types need to reflect the runtime behaviour).
  • This "wrapping" behaviour should be documented on the page for then.

Test code to reproduce

See above

Versions

Latest TS and Cypress

@jennifer-shehane
Copy link
Member

Feel free to open a PR here and in the docs. Check out our contributing doc.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 29, 2021

The code for this is done in cypress-io/cypress#15624, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 5, 2021

Released in 7.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v7.0.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: typings Issue related to Cypress types (for TypeScript)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants