diff --git a/packages/driver/src/cy/commands/querying.js b/packages/driver/src/cy/commands/querying.js index b88db3a12d47..36ff834fab27 100644 --- a/packages/driver/src/cy/commands/querying.js +++ b/packages/driver/src/cy/commands/querying.js @@ -409,6 +409,10 @@ module.exports = (Commands, Cypress, cy) => { filter = '' } + if (options.matchCase === true && _.isRegExp(text) && text.flags.includes('i')) { + throw new Error('cy.contains() content has i flag and matchCase is true. What is intended?') + } + _.defaults(options, { log: true, matchCase: true }) if (!(_.isString(text) || _.isFinite(text) || _.isRegExp(text))) { @@ -495,10 +499,6 @@ module.exports = (Commands, Cypress, cy) => { text = new RegExp(text.source, text.flags + 'i') // eslint-disable-line prefer-template } - if (options.matchCase === true && text.flags.includes('i')) { - throw new Error('cy.contains() content has i flag and matchCase is true. What is intended?') - } - // taken from jquery's normal contains method $expr.contains = (elem) => { let testText = normalizeWhitespaces(elem) diff --git a/packages/driver/test/cypress/integration/commands/querying_spec.js b/packages/driver/test/cypress/integration/commands/querying_spec.js index d006dfe5ddd6..572969957b2e 100644 --- a/packages/driver/test/cypress/integration/commands/querying_spec.js +++ b/packages/driver/test/cypress/integration/commands/querying_spec.js @@ -1936,6 +1936,10 @@ space matchCase: true, }) }) + + it('passes when "i" flag is used with undefined option', () => { + cy.get('#test-button').contains(/Test/i) + }) }) describe('subject contains text nodes', () => {