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

Cypress 12 Compatibility #115

Closed
elylucas opened this issue Nov 28, 2022 · 8 comments
Closed

Cypress 12 Compatibility #115

elylucas opened this issue Nov 28, 2022 · 8 comments

Comments

@elylucas
Copy link

Greetings from the @cypress-io team. Cypress 12 is coming out next week, and some changes might affect your plugin. One of the big changes is introducing a new API to register custom commands, which helps fix one of the oldest and most annoying issues with Cypress, the “Detached DOM” error.

For commands that are classified as queries (mainly used to return something like a DOM element), there is a new Cypress.Commands.addQuery method. The addQuery method greatly simplifies writing custom query commands and has the benefit of not encountering detached DOM errors.

If your plugin currently registers custom command “queries”, we recommend updating your plugin to use the new API for Cypress 12. Note the API is only going to be in Cypress 12 and newer.

To test out a prerelease version of Cypress 12, you can follow the instructions for installing a prerelease binary here, but instead of using the develop branch use the release/12.0.0 branch.

We recommend all plugin authors test their plugins against the Cypress 12 prerelease to check for compatibility.

If you have any questions, contact us by pinging me on this issue or in our Discord server.

You might find our Retry-ability Guide (updated to cover the latest changes), and Cypress 12 Migration Guide | Cypress Documentation helpful as well.

Thanks

@bahmutov
Copy link
Owner

bahmutov commented Nov 28, 2022 via email

@BlueWinds
Copy link

Hey Gleb - I agree that the ability to quickly do things like parseInt is a good idea, and it's been on my mind as a good quick follow-up for 12.1 or 12.2.

I'd prefer to take the approach of a new command, rather than overloading .then() further. I've been struggling to come up with a good name, if you have any thoughts.

  • .query()? This would align with "queries are a type of command", and the best I've come up with so far.
    • cy.get('input').invoke('val').query(parseInt).should('equal', 10) reads pretty naturally.
  • .call() - Another naming option for an entirely new command.
    • cy.get('input').invoke('val').call(parseInt).should('equal', 10)
  • Add another signature to .invoke() - it'd look like '.invoke(fnOrString, arg1, arg1, ...)`. If a string, we call a method on the subject, and if a function, we call it with the subject as the first arg.
    • cy.get('input').invoke('val').invoke(parseInt).should('equal', 10) also isn't bad.

@bahmutov
Copy link
Owner

This is what I would do: add a cy.map query command that would be take a pure or async pure function (yeah, I know, but still) and re-query it when needed

cy.get('li')
  .map('innerText') // or some kind of mechanism to access the props and values
  .map(parseInt)
  .should('deep.equal', [...])

I think the same could work for pure methods as well - if the argument is a string, and it is a method's name on the current subject, it should invoke it (and assume the subject does not change)

cy.get('li')
  .map('text')
  .should('equal', ...)

@BlueWinds
Copy link

Accepting a string argument and either accessing the value or calling that function are .its() and .invoke(), so we already have these. Overloading .invoke() so that it accepts a function as well as a string is definitely an option I'm considering.

.map() is a super good name though, better than the ones I'd come up with. 👍

@bahmutov
Copy link
Owner

yeah, all to make it simple to understand, just the question is of handling collections vs individual objects I think

@khitrenovich
Copy link

I might be late to the party, but I'm afraid map will be confusing - see Array or Lodash methods.

@bahmutov
Copy link
Owner

bahmutov commented Dec 6, 2022

I don't think so. This is specifically recreates the same behavior and is intended to. Or have any side effects (like array map but not array forEach)

@bahmutov
Copy link
Owner

Ok, this module works with Cypress v12, for extra queries see https://github.com/bahmutov/cypress-map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants