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

3.5K
Views
Encuentra elemento por id en react-testing-library

Estoy usando react-testing-libarary para probar mi aplicación de reacción. Por alguna razón, necesito poder encontrar el elemento por id y no data-testid . No hay forma de lograr esto en la documentación.

¿Hay una manera de lograr esto?

Tengo la salida renderizada como:

 const dom = render(<App />);

Estoy buscando algo en la línea de:

 const input = dom.getElemenById('firstinput'); //or const input = dom.getById('firstinput');
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Siento que ninguna de las respuestas realmente dio una solución completa, así que aquí está:

 const result = render(<SomeComponent />); const someElement = result.container.querySelector('#some-id');
over 4 years ago · Santiago Trujillo Report

0

Encontré una manera de hacer esto.

 import App from './App'; import { render, queryByAttribute } from 'react-testing-library'; const getById = queryByAttribute.bind(null, 'id'); const dom = render(<App />); const table = getById(dom.container, 'directory-table');

Espero que esto ayude.

over 4 years ago · Santiago Trujillo Report

0

Parece que tienes el nodo DOM como contenedor . Por lo tanto, debería poder llamar a .querySelector('#firstinput') con eso.

over 4 years ago · Santiago Trujillo 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!