Callback form of should chained off cy.window receives null when retried
See original GitHub issueCurrent behavior
My goal is to have a retriable check of a window
property that my app exposes. To achieve that, I’m using the callback form of should
.
The window object is correctly passed into the callback only for the first time. If the assertions fail and trigger a retry, the callback argument is null
. (See the repro code)
Maybe I missed something, but I went through the docs and I don’t think this is expected behavior.
Desired behavior
The callback of should
always receives the window
object
Test code to reproduce
it('retries should on window object', () => {
cy.window().should(win => {
// this logs <window> on the first run, but null on the next
cy.log('window =', win).then(() => {
// failing to trigger a retry
expect(true).to.equal(false)
})
})
})
Cypress Version
10.3.0
Other
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
then | Cypress Documentation
The callback function of . then() is not retried. It is unsafe to return DOM elements directly from the callback and then use...
Read more >Cypress Tips and Tricks - Gleb Bahmutov
readFile retries reading the file until the should(cb) passes // https://on.cypress.io/readfile cy.get('.new-todo') .type('todo A{enter}')
Read more >API Reference | Vitest
In Jest, TestFunction can also be of type (done: DoneCallback) => void . If this form is used, the test will not be...
Read more >Node.js v19.3.0 Documentation
Usage; Node-API version matrix; Environment life cycle APIs ... The callbacks will be inherited via the prototype chain:
Read more >Reactor 3 Reference Guide
Even though the first deployed artifact of a PATCH cycle will ... IDs are retrieved in less than 800ms or, if it takes...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Very interesting, thanks for the precise repro. I’m currently working in this area - how subjects are determined and how commands are retried - in relation to https://github.com/cypress-io/cypress/issues/7306.
The short version is that
should
is not really designed for this use case, and we don’t provide anything that is designed for this use case either. ^^;; I’m aiming to address that in my work. I’m going to assign myself here so I remember to follow up on this specific case.A temporary workaround would be to ensure that you don’t have any cypress commands inside your
should
callback:This passes; it’s only when the should callback contains other cypress commands that cy gets confused over what the subject should be during retries.
Released in
12.0.0
.This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v12.0.0, please open a new issue.