Cypress: `.each` changes scope for next dual-command (like `cy.contains()`)

Created on 3 Aug 2019  路  6Comments  路  Source: cypress-io/cypress

Current behavior:

When you call .each(), e.g. on a cy.get() command, it changes the scope for next cy.contains() command.

Possibly affects other commands, and possibly calls other than .each() change the scope, too.

Originally reported here.

Steps to reproduce: (app code and test code)

describe(`test`, () => {
    it(`test`, () => {
        cy.document().then(doc => {
            doc.body.innerHTML = `
                <div class="one"></div>
                <div>Search</div>
            `;
        });
        cy.get(`.one`)
            // comment this out for the next `cy.contains` to work properly
            .each(() => {});
        cy.contains(`Search`);
    });
});

image

Versions

cypress 3.4.1

pkdriver bug

All 6 comments

@dwelle thanks for reporting this. I can confirm I am seeing the same issue (as per my SO post)

Reproducible example from https://github.com/cypress-io/cypress/issues/5163

it('FAILS with contains after each', () => {
  cy.visit('https://www.google.com/')
  cy.contains('About')
  cy.get('input[type="submit"]').each(() => {})
  cy.contains('About')
})

it('passes with contains after then', () => {
  cy.visit('https://www.google.com/')
  cy.contains('About')
  cy.get('input[type="submit"]').then(() => { })
  cy.contains('About')
})

it('passes with contains after should', () => {
  cy.visit('https://www.google.com/')
  cy.contains('About')
  cy.get('input[type="submit"]').should(() => { })
  cy.contains('About')
})

Interesting to note that this seems to happen with custom dual-commands also (aside from just cy.contains() as noted in https://github.com/cypress-io/cypress/issues/6550

Another example from https://github.com/cypress-io/cypress/issues/6791

it('BUG? - breaks a following contains command', () => {
  cy.visit('https://example.cypress.io/commands/connectors')
  cy.get('.connectors-each-ul>li').each(() => {})
  cy.contains('Chai', { timeout: 10 })
})

The code for this is done in cypress-io/cypress#8712, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Released in 5.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.4.0, please open a new issue.

Was this page helpful?
0 / 5 - 0 ratings