Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
MaterialTable action buttons testing using jest and react test library

I have material-table with Add, Edit and Delete action icons. All are working. Now I want to write some unit test using jest and react test library.

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

For example the icon Add has title 'Add' and so on. onRowAdd(newRow) calls a handleRowAdd method to add new row to the table.

I want to write a unit test that asserts that the handleRowAdd method is called once when the icon/button add is clicked. I tried something like the following but didn't work

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

It seems Add button is not in the document because when I check expect(getAllByTitle('Add')).toHavelength(1) test passes but for expect(getAllByTitle('Add')).toBeInTheDocument(); test fails.

How can I access the Add button/icon as DOM element and then test the click event calls the handleRowAdd method?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda