-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Expect the assertion to eventually pass #15202
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
I would also like this, since I already implemented something similar and don't want to test async code without it anymore. No more random delay numbers which "work on my machine"™️ |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
Adding a new
expect().eventually()
orexpectEventually
functionality that is similar to vitest's poll and chai-wait-forIt will retry the assertion until it succeeds or hits a number of retries or exceeds an amount of time.
Motivation
Currently, we have our own wrapper that takes a function that contains expect statements and runs them until there are no errors. Our
e2e
tests have a lot of background jobs that reach out to external services so it's a toss up on when they will finish so just sleeping for a certain amount of time before the expect isn't a viable solution. We also try to avoid retesting entire suites since our tests take a long time to finish and when we switched to ourexpectEventually
wrapper, our test flakiness decreased and our CI runs completed much faster.There are some other third party packages out there that also provide the same functionality but a lot are no longer being maintained so it would be great if this was built into Jest to make
e2e
testing simpler.Example
This is how our current wrapper works which is one way this could be implemented
Another way could be
or the a more concise version where eventually returns the value of the provided function so it can be used later
Pitch
This makes e2e testing with asynchronous functionality, background jobs, and external services that may not be updated yet much easier to write. It also reduces flakiness in tests and improves the overall speed of the tests since only the failed expect statements get re-ran.
The text was updated successfully, but these errors were encountered: