Skip to content

feat: add asyncWrapper config #236

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

Merged
merged 1 commit into from
Apr 5, 2019
Merged

feat: add asyncWrapper config #236

merged 1 commit into from
Apr 5, 2019

Conversation

kentcdodds
Copy link
Member

@kentcdodds kentcdodds commented Apr 5, 2019

What: add asyncWrapper config

Why: At first glance you're probably thinking: "Oh no, no no. No way." But think for a moment that react-testing-library can't just export its own wait* APIs and make everything work, because the findBy* queries all use the waitForElement API that's exposed by dom-testing-library (not the one that would be wrapped by react-testing-library), so we have two options:

  1. Write wrapping code for every findBy* query that exists today and keep that updated in the future if new queries are ever added. This would include wrapping within/getQueriesForElement so the findBy* queries from those are are wrapped. In addition to wrapping all the wait* utilities.
  2. Allow configuration of the dom-testing-library wait* APIs as this PR does

I don't like either of those solutions, but I dislike solution 2 WAY less.

How:

Add a config option called asyncWrapper and wrap all the wait* APIs in that. The default just calls the callback so there's no real cost to doing it this way. I've tested this locally with and without my changes to react-testing-library and it works great (so people using a new dom-testing-library and an old react-testing-library will be fine). When I update react-testing-library I'll make sure to add a version bump to dom-testing-library so we don't wind up with the opposite situation.

Checklist:

  • Documentation added to the docs site N/A
  • Typescript definitions updated (I think so?)
  • Tests N/A
  • Ready to be merged

@kentcdodds
Copy link
Member Author

kentcdodds commented Apr 5, 2019

Note, the diff is worse than this really is. Checkout the changes in wait.js to see what's really going on in the others.

I cleaned it up significantly :)

@codecov
Copy link

codecov bot commented Apr 5, 2019

Codecov Report

Merging #236 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #236   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          13     13           
  Lines         293    298    +5     
  Branches       67     67           
=====================================
+ Hits          293    298    +5
Impacted Files Coverage Δ
src/wait-for-element.js 100% <100%> (ø) ⬆️
src/wait.js 100% <100%> (ø) ⬆️
src/config.js 100% <100%> (ø) ⬆️
src/wait-for-dom-change.js 100% <100%> (ø) ⬆️
src/wait-for-element-to-be-removed.js 100% <100%> (ø) ⬆️

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 393377a...d0d7943. Read the comment docs.

@kentcdodds kentcdodds merged commit ba251ed into master Apr 5, 2019
@kentcdodds kentcdodds deleted the pr/async-wrapper branch April 5, 2019 15:08
@kentcdodds
Copy link
Member Author

🎉 This PR is included in version 3.19.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

1 participant