Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

573
Views
createRoot (...): el contenedor de destino no es un elemento DOM en el archivo React Test

Estoy usando React-18.0.0 en mi proyecto y en el archivo de prueba recibo un error a continuación

createRoot(...): El contenedor de destino no es un elemento DOM.

Mi archivo de prueba es:

 import ReactDOM from 'react-dom/client'; import { render, screen } from "@testing-library/react"; import App from "./App"; const root = ReactDOM.createRoot(document.getElementById("root")); test("renders learn react link", () => { root.render(<App />); const linkElement = screen.getByText(/Hello React/i); expect(linkElement).toBeInTheDocument(); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su test usa root.render(<App />) mientras que la testing-library de React proporciona su propia función de render para usar dentro de una test

No es necesario recuperar la root y está causando el error que está mostrando.

Por lo tanto, aplique el siguiente cambio:

 // Remove root.render(<App />); // Replace with render(<App />); // Imported from @testing-library/react

Ejemplo de trabajo App.test.js :

 import { render, screen } from '@testing-library/react'; import App from './App'; test('renders learn react link', () => { render(<App />); const linkElement = screen.getByText(/this should exist/i); expect(linkElement).toBeInTheDocument(); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!