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: cy.contains and should('contain') handle backslash correctly. #20704

Merged
merged 5 commits into from Apr 26, 2022

Conversation

sainthkh
Copy link
Contributor

User facing changelog

cy.contains and should('contain') handle backslash correctly.

Additional details

  • Why was this change necessary? => Using backslash in cy.contains and should('contain') doesn't work.
  • What is affected by this change? => N/A

Any implementation details to explain?

Using backslash breaks the Sizzle selectors below:

const selector = `:contains('${escText}'), [type='submit'][value~='${escText}']`

return `${filter}:cy-contains(${textToFind}), ${filter}[type='submit'][value~=${textToFind}]`

For example, strings like <asdf\ escape the quotation marks and breaks the query.

So, I escaped the quotation marks.

But I had to solve a few more problems like:

  • redundant escapeQuotes functions. => create utils/escape.ts file and move them there.
  • should('contain') message are not shown correctly. => I had to escape the double quotes first.

How has the user experience changed?

cy.get('#backslashes').contains('"<OE_D]dQ\\')
cy.get('#escape-backslashes').should('contain', '"<OE_D]dQ\\')

Before: Fails.
After: Passes.

PR Tasks

  • Have tests been added/updated?
  • [na] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?
  • [na] Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 21, 2022

Thanks for taking the time to open a PR!

@@ -1277,6 +1277,36 @@ describe('src/cy/commands/assertions', () => {
})
})

// TODO: this suite should be merged with the suite above
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO is here because the test codes should be refactored a bit later.

The suite above format quotation marks actually has 3 subcategories:

  • format quotation marks
  • format strings
  • escape markdown

The name doesn't explain well about the tests.

It'll be handled after this PR is merged.

@sainthkh sainthkh marked this pull request as ready for review March 21, 2022 04:06
@sainthkh sainthkh requested a review from a team as a code owner March 21, 2022 04:06
@sainthkh sainthkh requested review from jennifer-shehane and removed request for a team March 21, 2022 04:06
@jennifer-shehane jennifer-shehane removed their request for review April 20, 2022 14:35
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 9, 2022

Released in 9.6.1.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cy.wrap(element).should('contain', textWithBackslash) fails
3 participants