Current 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)
Current behavior:
When
withinis used to find and return some element within some other element and then followed byshouldto 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)
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)