I recently upgraded my React App into React 18.2.0. and when trying to use the @testing-library/react library to run the tests, I got the error: createRoot(…): Target container is not a DOM element.
In my index.js file I`m using this code:
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
);
And when trying to test the rendering using the testing library and jest, some components are working and others are showing the error.
Please support!
I already set the root element in the index.html file as:
<div id="root" class="wrapper"></div>
I`m expecting an advise on how to resolve this error, and what may be the reasons behind this error.
Daoud El Gharib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.