-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Convert DOMPropertyOperations-test to createRoot #27911
Conversation
const container = document.createElement('div'); | ||
ReactDOM.render(<div title="Tip!" />, container); | ||
const root = ReactDOMClient.createRoot(container); | ||
await act(() => { | ||
root.render(<div title="Tip!" />); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty repetitive to have to write out for each unit test. What if we added a render function to internal-test-utils
that had a signature that matches RTL with the basics of what we need:
const {container, rerender} = render(<div title="Tip!" />, {container?: document.createElement('div')})
Internally root.render
is always wrapped in act
and rerender
takes JSX to render into the original root
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some value in not adding too many abstractions for tests which is why I started with 0 new abstractions here to see how it looks.
Wondering what others think about verbosity vs. avoiding extra abstractions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're generally against test utils because abstractions can be hard to change and it makes it difficult to debug or understand the use case when a test fails, which is why all the existing tests are verbose (some extremely so) even though we could have created a util.
The verbosity is also nice because it serves as documentation for how the APIs will be used by users, without needing to unwrap the abstractions we use in our tests.
Includes a fix for useOptimistic. React upstream changes: - facebook/react#27936 - facebook/react#27924 - facebook/react#27930 - facebook/react#27923 - facebook/react#27922 - facebook/react#27917 - facebook/react#27916 - facebook/react#27918 - facebook/react#27919 - facebook/react#27914 - facebook/react#27911 - facebook/react#27909 - facebook/react#27907 - facebook/react#27906 - facebook/react#27905
Includes a fix for useOptimistic. React upstream changes: - facebook/react#27936 - facebook/react#27924 - facebook/react#27930 - facebook/react#27923 - facebook/react#27922 - facebook/react#27917 - facebook/react#27916 - facebook/react#27918 - facebook/react#27919 - facebook/react#27914 - facebook/react#27911 - facebook/react#27909 - facebook/react#27907 - facebook/react#27906 - facebook/react#27905
Includes a fix for useOptimistic. React upstream changes: - facebook/react#27936 - facebook/react#27924 - facebook/react#27930 - facebook/react#27923 - facebook/react#27922 - facebook/react#27917 - facebook/react#27916 - facebook/react#27918 - facebook/react#27919 - facebook/react#27914 - facebook/react#27911 - facebook/react#27909 - facebook/react#27907 - facebook/react#27906 - facebook/react#27905 <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # --> Closes NEXT-2096
Convert DOMPropertyOperations-test to createRoot --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/27911). * facebook#27914 * __->__ facebook#27911
Convert DOMPropertyOperations-test to createRoot --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/27911). * #27914 * __->__ #27911 DiffTrain build for commit ef2859d.
Convert DOMPropertyOperations-test to createRoot
Stack created with Sapling. Best reviewed with ReviewStack.