feat(waitFor): allow returning a promise#782
Merged
Merged
Conversation
You can now return a promise in the waitFor callback and your callback will not be called again until the promise rejects. If the promise rejects, then the callback will be called again until it gets a promise which resolves or it times out.
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 8e16a0e:
|
kentcdodds
added a commit
to testing-library/testing-library-docs
that referenced
this pull request
Oct 12, 2020
This was referenced Oct 12, 2020
Codecov Report
@@ Coverage Diff @@
## master #782 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 25 25
Lines 703 713 +10
Branches 183 185 +2
=========================================
+ Hits 703 713 +10
Continue to review full report at Codecov.
|
Member
Author
|
@all-contributors please add @marcosvega91 for review |
Contributor
|
I've put up a pull request to add @marcosvega91! 🎉 |
|
🎉 This PR is included in version 7.25.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
kentcdodds
added a commit
to testing-library/testing-library-docs
that referenced
this pull request
Oct 12, 2020
superT999
added a commit
to superT999/testing-library-docs
that referenced
this pull request
Feb 13, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You can now return a promise in the waitFor callback and your callback
will not be called again until the promise rejects. If the promise
rejects, then the callback will be called again until it gets a promise
which resolves or it times out.
What: feat(waitFor): allow returning a promise
Why: So we don't have to do weird things like this: https://github.com/kentcdodds/bookshelf/pull/83/files#diff-f3caa0e4f827bc632c53d30ddb2aeb60R26-R29
Specifically, we need to
waitForsomething, but the callback has to do something asynchronous to determine whether we can continue our test. Today,waitFordoes not support this... Until now...How: Store a promiseStatus and if the waitFor callback returns a "thennable" then we attach our own handler onto the promise and update the promiseStatus to be "pending". So long as the promiseStatus is "pending" we will not call the callback again.
Checklist:
docs site