`within` followed by `should` permanently limits scope
See original GitHub issueCurrent behavior:
When within
is used to find and return some element within some other element and then followed by should
to test the returned element, this breaks all subsequent commands (all, not just in the same chain) by permanently setting the root to the aforementioned other element.
In other words, cy.get('#scope').within(() => cy.get(…)).should(…)
breaks the rest of the test, because it makes it impossible to find anything outside #scope
.
Desired behavior:
cy.get(…).within(() => cy.get(…)).should(…)
shouldn’t impact subsequent commands at all. E.g. cy.get(…)
used after it should search the entire document as usual.
Steps to reproduce: (app code and test code)
<div id="foo"><p>foo</p></div>
cy.root().should('match', 'html') // passes, as it always should
cy.get('#foo')
.within(() => cy.get('p')) // returns `#foo p`
.should('match', 'p') // passes, but causes the scope of preceding `within` to become global
cy.root().should('match', 'html') // fails! root is still `div#foo`
Obviously this example is contrived, it’s just a minimum reproducible sample.
Versions
Cypress 3.3.2 Chrome 75.0.3770.100 (Official Build) (64-bit) MacOS 10.14.5 (18F132)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:12 (2 by maintainers)
Top GitHub Comments
@jennifer-shehane : Any news on this issue ?
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.