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

141
Views
Prueba de los botones de acción de MaterialTable usando la biblioteca de pruebas jest y react

Tengo una tabla de materiales con íconos de acción Agregar, Editar y Eliminar. Todos están trabajando. Ahora quiero escribir una prueba de unidad usando la biblioteca de prueba de broma y reacción.

 import AddBox from "@material-ui/icons/AddBox"; const tableIcons = { Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />),

Por ejemplo, el icono Agregar tiene el título 'Agregar' y así sucesivamente. onRowAdd(newRow) llama a un método handleRowAdd para agregar una nueva fila a la tabla.

Quiero escribir una prueba unitaria que afirme que el método handleRowAdd se llama una vez cuando se hace clic en el ícono/botón agregar. Intenté algo como lo siguiente pero no funcionó

 const {getAllByTitle}= render(<ContentTable/>) const addButton = getAllByTitle('Add') fireEvent.click(addButton) expect(handleRowAdd.calls).toHavelength(1)

Parece que el botón Agregar no está en el documento porque cuando compruebo expect(getAllByTitle('Add')).toHavelength(1) la prueba pasa pero para expect(getAllByTitle('Add')).toBeInTheDocument(); la prueba falla.

¿Cómo puedo acceder al botón/icono Agregar como elemento DOM y luego probar el evento de clic llama al método handleRowAdd?

about 4 years ago · Juan Pablo Isaza
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!