question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`within` followed by `should` permanently limits scope

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Prashant-Kancommented, Jan 27, 2020

@jennifer-shehane : Any news on this issue ?

0reactions
cypress-bot[bot]commented, Oct 14, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Practice - Position Statements - Texas Board of Nursing
The RN takes responsibility and accepts accountability for practicing within the legal scope of practice and is prepared to work in all health...
Read more >
1910.21 - Scope and definitions.
Equivalent means alternative designs, equipment, materials, or methods, that the employer can demonstrate will provide an equal or greater degree of safety for ......
Read more >
Six (yes six!) constraints - PMI
In most cases there are no “ranges of acceptability” for scope: we asked for particular items, and we expect to get them –...
Read more >
HUD - 1378 CHG-15 CHAPTER 1 Scope, Definitions and ...
3) Where an owner either evicts a tenant or fails to renew a lease in order to sell a property as “vacant” to...
Read more >
Learn about retention policies & labels to retain or delete
Competitive research that needs to be retained for a specific period and then permanently deleted. Work visas that must be marked as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found