From 1b53324eb48c1f5e450836cedce6fcf2084bc685 Mon Sep 17 00:00:00 2001 From: KHeo Date: Thu, 16 Jan 2020 12:03:57 +0900 Subject: [PATCH] Fix the valid case that throws an error. --- packages/driver/src/cy/commands/querying.js | 8 ++++---- .../test/cypress/integration/commands/querying_spec.js | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) 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', () => {