Cypress: cy.contains() should be case-insensitive by default

Created on 26 Feb 2020  路  1Comment  路  Source: cypress-io/cypress

Current behavior:

cy.contains() argument matchCase defaults to true.

Desired behavior:

cy.contains() argument matchCase defaults to false and can be set to true for case-sensitive matching.

As already stated by @jennifer-shehane in this issue, I find it quite annoying to have to change my tests cy.contains()s whenever I change capitalization and would generally prefer case-insensitive matching as for me, that would be closer to the easy way of creating tests Cypress is always promoting.

Versions

Cypress 4.0.2
Chromium, Manjaro Linux

Most helpful comment

I would recommend just overwriting the .contains command, so that every time you use it it has matchCase set to false.

Cypress.Commands.overwrite('contains', (originalFn, subject, filter, text, options = {}) => {
  // determine if a filter argument was passed
  if (typeof text === 'object') {
    options = text
    text = filter
    filter = undefined
  }

  options.matchCase = false

  return originalFn(subject, filter, text, options)
})

We didn't want to make a massive breaking change for everyone (which this would have been) in 4.0 when we released this.

Adding this feature is not something we see as within our scope of feature work, so we will be closing this issue. We will reconsider and reopen if we see this issue gains more 馃憤 or comments in support.

>All comments

I would recommend just overwriting the .contains command, so that every time you use it it has matchCase set to false.

Cypress.Commands.overwrite('contains', (originalFn, subject, filter, text, options = {}) => {
  // determine if a filter argument was passed
  if (typeof text === 'object') {
    options = text
    text = filter
    filter = undefined
  }

  options.matchCase = false

  return originalFn(subject, filter, text, options)
})

We didn't want to make a massive breaking change for everyone (which this would have been) in 4.0 when we released this.

Adding this feature is not something we see as within our scope of feature work, so we will be closing this issue. We will reconsider and reopen if we see this issue gains more 馃憤 or comments in support.

Was this page helpful?
0 / 5 - 0 ratings