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.

Can I have cy.task retry until assertion passes?

See original GitHub issue

cy.task is great but does not retry its action, even if it is idempotent code. In situations like “checking if the database has been updated” (see https://github.com/cypress-io/cypress-example-recipes/commit/e6f3b4c2cc7731c1ec9936426bb71b5ecb9af9ae#diff-11f8d1f12b6eb04ff4abd710d5e9d786) it would be perfect NOT to implement “retry until my assertion passes” logic in Node, but instead have cy.task behave like a regular Cypress command.

Something like this

cy.taks('find item in the database').should('deep.equal', {id: 1, text: 'something'})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bahmutovcommented, Jun 13, 2018

better formatting

cy.task('reset:db').then(...)
// "reset:db" runs once
cy.task('db:select', title, {timeout: 5000, idempotent: true}).should('deep.equal', ...)
// "db:select" is retried until the assertion passes or 5 seconds timeout reached
0reactions
jennifer-shehanecommented, Nov 9, 2020

Closing as resolved since there is a workaround outlined.

If you’re experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retry-ability - Cypress Documentation
Queries and assertions are always executed in order, and always retry 'from the top'. If you have multiple assertions, Cypress will retry until...
Read more >
Incredibly Powerful cy.task - Gleb Bahmutov
The cy.task command does not retry. Because Cypress has no idea what your task is going to do - it probably is NOT...
Read more >
Cypress not retrying assertion - Stack Overflow
From reading about Cypress retry-ability, my understanding is that the should assertion should keep trying until timeout, which is set as " ...
Read more >
What are flaky tests in Cypress and how to prevent them?
You know that you have a flaky test when it passes when run ... and the assertion fails, Cypress will only retry the...
Read more >
CRUD API testing a deployed service with Cypress using cy ...
What you will learn: CRUD testing any API. cy.task ... There are 4 ways to do assertions with Cypress, 3 of them have...
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