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

110
Vistas
Trying to test two check boxes in modal react testing library

I have a modal that has two checkboxes. One is checked and the other is not (by default). I am trying to write a test that finds box checkboxes with their default values.

            <Checkbox
              float="left"
              paddingTop="20px"
              mr="10px"
              borderColor="gray.50"
            />
            <TextContainer textStyle="textSm" fontWeight="normal" pt="25px">
              Make Account Admin
            </TextContainer>


            <Checkbox
              defaultChecked={welcomeEmail}
              float="left"
              paddingTop="1%"
              paddingBottom="5%"
              mr="10px"
              borderColor="gray.50"
            />
            <TextContainer textStyle="textSm" fontWeight="normal" pt="2px">
              Send welcome emails
            </TextContainer>

I tried queryByRole but it found multiple checkboxes. So I am trying to see how I can distinguish between both. any thoughts.

const checkbox = screen.queryByRole('checkbox');
expect(checkbox).toBeChecked(); 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If the postion of these checkboxes remains constant when this page is rendered, then you could find all of them using getAllByRole (this returns all checkboxes found in an array) and then assert their values e.g.

const checkboxes = screen.getAllByRole('checkbox');
expect(checkboxes[0]).not.toBeChecked();
expect(checkboxes[1]).toBeChecked();
about 4 years ago · Juan Pablo Isaza Denunciar
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