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

187
Views
Migración de enzima a biblioteca de pruebas de reacción: cómo seleccionar el elemento n de la lista

tengo este codigo:

 wrapper.find('.table-year-head button').at(1).simulate('click'); wrapper .find('.table-months') .at(1) .find('input[type="checkbox"]') .forEach(node => { expect(node.props().checked).toEqual(true); });

Sé que puedo usar data-testid para los selectores, pero ¿cómo puedo seleccionar el enésimo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede utilizar una consulta getAllBy :

 const table = wrapper.getAllByRole('table')[1] fireEvent.click(within(table).getByRole('button'));

El problema es que no podría usar los selectores de CSS de la forma en que lo hace con Enzyme. La biblioteca de prueba de React tiene que ver con la semántica. Le recomendaría agregar etiquetas a sus tablas usando el atributo aria-label :

 <table className="years" aria-label="Year table"> ...

De esta manera, serías capaz de hacer:

 const yearTable = wrapper.getByRole('table', {name: 'Year table'}); fireEvent.click(within(yearTable).getByRole('button')); const monthTable = screen.getByRole('table', {name: 'February table'}); const checkbox = within(monthTable).getByRole('checkbox') fireEvent.click(checkbox); expect(checkbox).toBeChecked();
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!