Skip to content
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

feat(config): Add unstable_advanceTimersWrapper #1022

Merged
merged 10 commits into from
Sep 11, 2021

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Sep 5, 2021

What:

Add unstable_advanceTimersWrapper config option

Why:

Required for backwards compatible support of concurrent rendering in React 18.
Example usage for fixing testing-library/react-testing-library#937:

diff --git a/src/pure.js b/src/pure.js
index a25000e..041e78e 100644
--- a/src/pure.js
+++ b/src/pure.js
@@ -20,6 +18,15 @@ configureDTL({
   },
 })
 
+if (typeof React.startTransition !== undefined) {
+  configureDTL({
+    advanceTimersWrapper: cb => {
+      return act(cb)
+    },
+    asyncWrapper: cb => cb(),
+  })
+}
+
 // Ideally we'd just use a WeakMap where containers are keys and roots are values.
 // We use two variables so that we can bail out in constant time when we render with a new container (most common use case)
 /**

How:

Wrap advancing timers for jest in getConfig.advanceTimersWrapper().

Checklist:

  • [ ] Documentation added to the
    docs site
    No documentation yet.
  • Tests
  • TypeScript definitions updated
  • Ready to be merged

@eps1lon eps1lon added the enhancement New feature or request label Sep 5, 2021
@eps1lon eps1lon changed the title Use same interval handler in all supported clocks feat(config): Add advanceTimersWrapper Sep 5, 2021
@codecov
Copy link

codecov bot commented Sep 5, 2021

Codecov Report

Merging #1022 (f35d8c1) into main (c7ba193) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main     #1022   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines          916       920    +4     
  Branches       286       286           
=========================================
+ Hits           916       920    +4     
Flag Coverage Δ
node-12 100.00% <100.00%> (ø)
node-14 100.00% <100.00%> (?)
node-16.9.1 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/config.ts 100.00% <100.00%> (ø)
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 c7ba193...f35d8c1. Read the comment docs.

@eps1lon eps1lon marked this pull request as ready for review September 5, 2021 12:01
@eps1lon eps1lon changed the title feat(config): Add advanceTimersWrapper feat(config): Add unstable_advanceTimersWrapper Sep 5, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 5, 2021

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 f35d8c1:

Sandbox Source
react-testing-library-examples Configuration

@eps1lon eps1lon force-pushed the feat/advance-timers-wrapper branch 2 times, most recently from 7c8411e to 9d12234 Compare September 5, 2021 12:34
@eps1lon eps1lon marked this pull request as draft September 5, 2021 12:34
@eps1lon eps1lon marked this pull request as ready for review September 7, 2021 08:05
@eps1lon
Copy link
Member Author

eps1lon commented Sep 7, 2021

Going to merge soon-ish to unblock an alpha release of testing-library/react-testing-library#937. It's behind an unstable prefix and not documented so it is safe to change the API freely.

@eps1lon eps1lon merged commit 45830f5 into testing-library:main Sep 11, 2021
@eps1lon eps1lon deleted the feat/advance-timers-wrapper branch September 11, 2021 09:12
@github-actions
Copy link

🎉 This PR is included in version 8.5.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
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant