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

169
Views
finding properties from an array of objects/testing

Beginner on react testing here, any idea/suggestion on what would be good way to achieve this, my data.map gives an array of objects which contains identifiers and names, i would like to test those, if those properties have text content like that. What i did is to use 'role' but then on role it seems we cant use made up names, so how would do this ?

My test:

  test("test clicking ListItem", () => {
    const Items = [{ identifier: "0-0-0-2", name: "Camera 1" }];

    render(
      <Provider store={store}>
        <SelectionList
          classes={{ button_basic: "" }}
          action={"cameras"}
          actionArgs={""}
          onUpdateClick={onClickCallback}
          onDeleteClick={onClickCallback}
          onDetailsClick={onClickCallback}
        />
      </Provider>
    );
    const SelectionCardElement = screen.getAllByRole("mapData");
    expect(SelectionCardElement[0]).toHaveTextContent(Items[0].identifier);
    expect(SelectionCardElement[0]).toHaveTextContent(Items[0].name);
  });

Code:

 const data = currentItem[props.action as keyof typeof currentItem];
  let childList: React.ReactElement | string = "";
  if (data && data.length > 0) {
    childList = (
      <Collapse
        key={itemListCollapseKey}
        in={collapseStates[itemListCollapseKey]}
        unmountOnExit
      >
        {data.map((el: ConnectedSelectionListProps) => (
          <List role="mapData" key={keyFromEl(el) + "sublist"}>
            {console.log("renders: ", el.name, el)}
            {renderListItem(keyFromEl(el), el.name, el)}
          </List>
        ))}
      </Collapse>
    );
  }

List and Collapse comes from "@material-ui/core/"

my childList:

return (
    <List component="div" data-testid="SelectionListt">
      <ListItem
        key={props.action + "-header"}
        button
        onClick={(event) => {
          handleExpandClick(event, itemListCollapseKey);
        }}
      >
        <ListItemAvatar>{renderItemsIcon()}</ListItemAvatar>
        <ListItemText>
          <Trans i18nKey={"selection." + props.action}>{props.action}</Trans>
        </ListItemText>
        {collapseStates[itemListCollapseKey] ? <ExpandLess /> : <ExpandMore />}{" "}
      </ListItem>

      {childList}
    </List>
  );

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!