Update Testing Library for React 19 compat#75340
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 3.02 MB ℹ️ View Unchanged
|
|
I guess that using either |
tyxla
left a comment
There was a problem hiding this comment.
One way to address this woud be to avoid using user-event and @ariakit/test utils together.
If that's our way forward for now, can we enforce it via a custom ESLint rule perhaps?
If we end up doing that, let's document the context and potential next steps right there in the rule.
|
Another thing we could do is to fixup the function userEventSetup() {
userEvent.setup();
/* Fix the botched `HTMLElement.prototype` by adding `writable: true` */
const { focus, blur } = HTMLElement.prototype;
Object.defineProperties( HTMLElement.prototype, {
focus: { configurable: true, value: focus, writable: true },
blur: { configurable: true, value: blur, writable: true },
} );
}This would make the two libs compatible again. |
Then this would be my favourite fix, with the least amount of changes to the existing code. We should add a comment to explain why we're doing it, and maybe even link to the |
|
Asking from a place of ignorance: Why do we use both (Although the lack of recent maintainer activity in |
Ariakit-based components tend to need |
d2f8a6d to
8609341
Compare
|
All issues in this PR are now solved and it's ready. After trying out a few alternatives, I solved the The |
|
Glad we could fix this in a centralized way 👍 |
8609341 to
7dbaae9
Compare
For the React 19 upgrade (#71336) we need to upgrade
@testing-library/react. The 14.3.0 version we're currently using doesn't support React 19: it declares its React peer dependencies as^18, and also uses React 18 types.One thing that will probably cause us headaches is
@testing-library/user-event. We can't use the latest version because it's not compatible with@ariakit/test, and the needed fix (testing-library/user-event#1265) hasn't been released for a year. That's why @aduth had to pin an older version in #74396. This older version depends on ancient@types/[email protected], two major versions behind.One way to address this woud be to avoid using
user-eventand@ariakit/testutils together. As soon as you use the customrenderorclickutils from Ariakit, and also initialize theuser-eventlibrary, they start fighting over patching the nativeElement.prototype.focusmethod. We have 5 test suites where this happens. One of the libraries would need to be removed from these.