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.

Chaining after within: Return inner chainable?

See original GitHub issue

Current behavior:

cy.get(`.parent`).within(() => cy.get(`.child`))

Yields the parent if I’m correct (?).

Desired behavior:

I’d expect the previous command to yields the selected child.

It would be very helpful so that when we have a function or a getter to retrieve an element we could chain them.

Versions

Cypress 3.2.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, May 22, 2019

I think we will close for now but track if anyone else requests this feature.

1reaction
jennifer-shehanecommented, May 7, 2019

Yeah, you could use .then() to return the inner “promise” https://on.cypress.io/then#Yields but then you’d have to scope the inner commands yourself, since you’d be losing the within scope.

Something like:

/// code
return DOM.card.self.then(($el) => cy.wrap($el).find(`.title`));
/// code
Read more comments on GitHub >

github_iconTop Results From Across the Web

Promises chaining - The Modern JavaScript Tutorial
A Promise keeps an internal state. It calls the handler wrapped in a try...catch block and stores the error. That is why asynchronous...
Read more >
How can I chain two observables and return the inner ...
I think its not returning the correct observable. It seems to just return the getSpecificSegment and then the inner observable doesn't execute, ...
Read more >
Understanding Method Chaining In Javascript - segunolalive
This example shares lots of similarities with the ChainAble class shown before. It contains methods that do some things, then return this.
Read more >
Understanding Cypress's command execution order and ...
A Chainable object is what all Cypress commands return, and are what is stored in the queue of commands mentioned above. As explained,...
Read more >
Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
This is an idiomatic pattern in JavaScript, but it gets verbose when the chain is long, and it's not safe. For example, if...
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