Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda