You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enables you to work with the subject yielded from the previous command.
It sounds like we can work with any subject, but in fact we can only work with subject of length > 0, with some workaround (see following example below), yet without all this documented in official doc, and hence being pretty not obvious to the majority of users who then ask questions like this.
More over, the official docs in the Differences section tells that .should is different from .then in context of retriability in the fact that ".should retries but then – no" (at least as I understood it). In fact, if subject will be of 0 length - the previous chain will be retried waiting for subject to be > 0. That looks kind of inconsistent (at least without additional and currently absent – explanation in docs...)
So here is an example:
describe('cy.then(callback)',()=>{it('fails to run code inside callback if subject.length = 0',()=>{browser.visit('https://todomvc.com/examples/emberjs/')// error: «Timed out retrying after 4000ms: Expected to find element: #todo-list>li, but never found it.»cy.get('#todo-list>li').then($subject=>{expect($subject).to.have.length(0)})})it('callback is called and passed for subject.length = 0 after explicit .should',()=>{browser.visit('https://todomvc.com/examples/emberjs/')cy.get('#todo-list>li').should('have.length.at.least',0).then($subject=>{expect($subject).to.have.length(0)})})})
My points are the following:
Current behavior looks pretty inconsistent with what can be found in docs. At least docs should be updated with additional explanation.
For my taste such behaviour is too limited. Why would we need to limit calling callback via then, where we would want to do some "low level stuff" tuned to our context without limitations? I write some plugins for cypress where I want to extend it with custom retriability and assertion logic, but I can't do this because even .then does not give me full consistent low level access to the subject from previous commands (i can't disable retriability in case of subject=0...) I vote for the corresponding feature request to remove such limitation.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In official .then command docs we see at the beginning:
It sounds like we can work with any subject, but in fact we can only work with subject of length > 0, with some workaround (see following example below), yet without all this documented in official doc, and hence being pretty not obvious to the majority of users who then ask questions like this.
More over, the official docs in the Differences section tells that
.should
is different from.then
in context of retriability in the fact that ".should retries but then – no" (at least as I understood it). In fact, if subject will be of 0 length - the previous chain will be retried waiting for subject to be > 0. That looks kind of inconsistent (at least without additional and currently absent – explanation in docs...)So here is an example:
My points are the following:
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions