Skip to content

feat(waitFor): allow returning a promise#782

Merged
kentcdodds merged 1 commit into
masterfrom
pr/wait-for-promise
Oct 12, 2020
Merged

feat(waitFor): allow returning a promise#782
kentcdodds merged 1 commit into
masterfrom
pr/wait-for-promise

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Oct 12, 2020

Copy link
Copy Markdown
Member

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 waitFor something, but the callback has to do something asynchronous to determine whether we can continue our test. Today, waitFor does 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:

  • Documentation added to the
    docs site
  • Tests
  • Typescript definitions updated
  • Ready to be merged

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.
@codesandbox-ci

Copy link
Copy Markdown

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:

Sandbox Source
kentcdodds/react-testing-library-examples Configuration

@codecov

codecov Bot commented Oct 12, 2020

Copy link
Copy Markdown

Codecov Report

Merging #782 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #782   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          703       713   +10     
  Branches       183       185    +2     
=========================================
+ Hits           703       713   +10     
Impacted Files Coverage Δ
src/wait-for.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03cfef8...8e16a0e. Read the comment docs.

@marcosvega91 marcosvega91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me is good :)

@kentcdodds
kentcdodds merged commit 4e5e533 into master Oct 12, 2020
@kentcdodds
kentcdodds deleted the pr/wait-for-promise branch October 12, 2020 22:36
@kentcdodds

Copy link
Copy Markdown
Member Author

@all-contributors please add @marcosvega91 for review

@allcontributors

Copy link
Copy Markdown
Contributor

@kentcdodds

I've put up a pull request to add @marcosvega91! 🎉

@testing-library-bot

Copy link
Copy Markdown

🎉 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants