Skip to content

Commit

Permalink
fix: show correct error message. (#21388)
Browse files Browse the repository at this point in the history
Co-authored-by: Rachel <rachel@cypress.io>
  • Loading branch information
sainthkh and rachelruderman committed May 18, 2022
1 parent fdaf5fb commit 7aa9b20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,16 @@ describe('src/cy/commands/querying', () => {
cy.get('#backslashes').contains('"<OE_D]dQ\\')
})

// https://github.com/cypress-io/cypress/issues/21108
it('shows correct error message when regex starts with =(equals sign)', () => {
cy.on('fail', (err) => {
expect(err.message).to.include('Expected to find content')
})

cy.visit('fixtures/dom.html')
cy.contains(/=[0-6]/, { timeout: 100 }).should('have.text', 'a=2')
})

describe('should(\'not.exist\')', () => {
it('returns null when no content exists', () => {
cy.contains('alksjdflkasjdflkajsdf').should('not.exist').then(($el) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/driver/src/config/jquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ $.find.matchesSelector = function (elem, expr) {
return matchesSelector.apply(_this, args)
},
catchFn (e) {
// https://github.com/cypress-io/cypress/issues/21108
// When regex starts with =, it is a syntax error when nothing found.
// Because Sizzle internally escapes = to handle attribute selectors.
// @see https://github.com/jquery/sizzle/blob/20390f05731af380833b5aa805db97de0b91268a/external/jquery/jquery.js#L4363-L4370
if (e.message.includes(`Syntax error, unrecognized expression: :cy-contains('`)) {
return false
}

throw e
},
finallyFn () {
Expand Down

3 comments on commit 7aa9b20

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7aa9b20 May 18, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.2/linux-x64/develop-7aa9b20592c03049baf42ab260c666cb5c3f4cc6/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7aa9b20 May 18, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.2/win32-x64/develop-7aa9b20592c03049baf42ab260c666cb5c3f4cc6/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7aa9b20 May 18, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.2/darwin-x64/develop-7aa9b20592c03049baf42ab260c666cb5c3f4cc6/cypress.tgz

Please sign in to comment.