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

120
Views
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 answers
Answer question

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 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!