5

Im using rerender and renderHook in react testing library. Recently upgraded react version to 18. Got below error in one of the test case.

console.error Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot

rerender(); renderHook(() => abc());

Since, im not using render why the warning is pointing rerender and renderHook as render.

Could you please point how to dig this issue further.

John
  • 2,035
  • 13
  • 35
  • 44

2 Answers2

10

instead of using "@testing-library/react-hooks" use "@testing-library/react"

import { renderHook, act } from "@testing-library/react";
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
ALireza Bagheri
  • 101
  • 1
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 13 '23 at 09:58
0

Perhaps all you need to do is to update the version of @testing-library. Try the followings,

npm i --save-dev @testing-library/react@latest
npm i --save-dev @testing-library/jest-dom@latest
npm i --save-dev @testing-library/user-event@latest

To be clear, it's good to empty your node_modules and reinstall all.

rm -rf ./node_modules
npm i

This is how my case had been resolved.

Hoon
  • 637
  • 5
  • 10