Skip to content

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

Closed
@jerelmiller

Description

@jerelmiller

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions