Skip to content

Commit 7aa9b20

Browse files
sainthkhRachel
andauthored
fix: show correct error message. (#21388)
Co-authored-by: Rachel <rachel@cypress.io>
1 parent fdaf5fb commit 7aa9b20

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/driver/cypress/integration/commands/querying/querying_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,16 @@ describe('src/cy/commands/querying', () => {
12301230
cy.get('#backslashes').contains('"<OE_D]dQ\\')
12311231
})
12321232

1233+
// https://github.com/cypress-io/cypress/issues/21108
1234+
it('shows correct error message when regex starts with =(equals sign)', () => {
1235+
cy.on('fail', (err) => {
1236+
expect(err.message).to.include('Expected to find content')
1237+
})
1238+
1239+
cy.visit('fixtures/dom.html')
1240+
cy.contains(/=[0-6]/, { timeout: 100 }).should('have.text', 'a=2')
1241+
})
1242+
12331243
describe('should(\'not.exist\')', () => {
12341244
it('returns null when no content exists', () => {
12351245
cy.contains('alksjdflkasjdflkajsdf').should('not.exist').then(($el) => {

packages/driver/src/config/jquery.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ $.find.matchesSelector = function (elem, expr) {
5151
return matchesSelector.apply(_this, args)
5252
},
5353
catchFn (e) {
54+
// https://github.com/cypress-io/cypress/issues/21108
55+
// When regex starts with =, it is a syntax error when nothing found.
56+
// Because Sizzle internally escapes = to handle attribute selectors.
57+
// @see https://github.com/jquery/sizzle/blob/20390f05731af380833b5aa805db97de0b91268a/external/jquery/jquery.js#L4363-L4370
58+
if (e.message.includes(`Syntax error, unrecognized expression: :cy-contains('`)) {
59+
return false
60+
}
61+
5462
throw e
5563
},
5664
finallyFn () {

0 commit comments

Comments
 (0)