Skip to content

Commit

Permalink
Fix the valid case that throws an error.
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Jan 16, 2020
1 parent 2533c1b commit 1b53324
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/driver/src/cy/commands/querying.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 1b53324

Please sign in to comment.