Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress DOM alias retries to re-run .blur command #15793

Closed
bahmutov opened this issue Apr 5, 2021 · 3 comments
Closed

Cypress DOM alias retries to re-run .blur command #15793

bahmutov opened this issue Apr 5, 2021 · 3 comments
Labels
topic: alias Issues with alias creation or use type: duplicate This issue or pull request already exists

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Apr 5, 2021

Cypress v6.8.0

https://github.com/cypress-io/cypress-test-tiny/tree/alias-blur

Imagine the spec

/// <reference types="cypress" />
it('uses the alias', () => {
  // cy.visit('/')
  cy.visit('index.html')
  cy.focused().should('have.id', 'fname').blur()

  // completely unrelated field
  cy.contains('Child div').as('child').should('be.visible')

  // re-render the label
  cy.get('button').click()

  cy.get('@child')
  // just querying it again works
  // cy.contains('Child div').as('child').should('be.visible')
})

The button click re-draws the relevant DOM node

document.getElementById('work').addEventListener('click', () => {
  document.getElementById('parent').innerHTML = `
    <div id="child">Updated Child div</div>
  `
})

Because of the button click, the original DOM alias @child is no longer attached to the DOM, thus Cypress tries to re-query the chain of commands. When this runs (use Chrome v91+ to get around #6207) we get an attempt to re-run the .blur command

Screen Shot 2021-04-05 at 4 49 28 PM

@bahmutov bahmutov added type: bug topic: alias Issues with alias creation or use labels Apr 5, 2021
@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 5, 2021

Seems it thinks the original cy.contains is a child command, even if it starts

cy.contains('Child div').as('child').should('be.visible')

Screen Shot 2021-04-05 at 5 34 34 PM

@bahmutov
Copy link
Contributor Author

bahmutov commented Apr 5, 2021

@bkucera would/should cy.contains be a parent command or a child command this test?

cy.visit('/')
cy.contains('some text')

Right now it thinks cy.contains is a child command of cy.visit but I seriously doubt this is correct

@jennifer-shehane
Copy link
Member

cy.contains() reruns queries when there's an alias. It's very very weird behavior.

Duplicate of #7413

@jennifer-shehane jennifer-shehane added type: duplicate This issue or pull request already exists and removed type: bug labels May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: alias Issues with alias creation or use type: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants