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

Migrate tests from @testing-library/react-hooks to @testing-library/react #10333

Closed
jerelmiller opened this issue Dec 5, 2022 · 1 comment · Fixed by #10415
Closed

Migrate tests from @testing-library/react-hooks to @testing-library/react #10333

jerelmiller opened this issue Dec 5, 2022 · 1 comment · Fixed by #10415

Comments

@jerelmiller
Copy link
Member

jerelmiller commented Dec 5, 2022

React hooks testing library does not have React 18 support and has migrated renderHook to the core @testing-library/react library. As stated in the README:

As part of the changes for React 18, it has been decided that the renderHook API provided by this library will instead be included as official additions to both react-testing-library (PR) and react-native-testing-library (PR) with the intention being to provide a more cohesive and consistent implementation for our users.

With the introduction of suspense to Apollo client, its become more obvious that we need to work with a version of renderHook that works with React 18 since it uses the new concurrent rendering APIs. To ensure Apollo client works with React 18 out of the box, it's imperative we run our React 18 tests in a way that we expect our users will use React 18.

There is one tricky issue though... with the migration of renderHook to the core library, we can't run our React 17 tests through it. The suggestion is to use @testing-library/react^12 (which we do), but unfortunately the renderHook function is not exported from that version. We should be able to patch that behavior using patch-package. In fact, the suspense PR does this for us. Once this change is in main, we can look to slowly update our tests over time to use hook from the core testing library.

We can use this migration guide to migrate over when we are ready.

@alessbell
Copy link
Contributor

I have a few branches with these tests migrated already :) will be great to get the patch-package diff in there and then I will pick this up.

@alessbell alessbell self-assigned this Jan 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants