I have a component:
const TextWithIcons = (props: Props) => {
const {
cellText,
isSubline,
maxWrapLines,
textFieldWidth,
iconList,
hasIconTooltips
} = props
const MAX_ICONS_TO_SHOW = 5
const icons = iconList.slice(0, MAX_ICONS_TO_SHOW).map(icon => (
<Tooltip
title={icon}
duration="10"
disabled={!hasIconTooltips}
arrow
key={icon}
>
<SvgIcon svg={icon} key={icon} />
</Tooltip>
))
return (
<>
<TextWithIconsContainers>
<IconsListContainer>{icons}</IconsListContainer>
<TextField
cellText={cellText}
isSubline={isSubline}
maxWrapLines={maxWrapLines}
width={textFieldWidth}
/>
</TextWithIconsContainers>
</>
)
}
That uses several sub-components to display an array of icons. It works on my client wonderfully, and even renders in my storybook as intended. However when I try to test it using RTL and Jest:
test('should render, in general', () => {
render(<TextWithIcons cellText={'test'} iconList={[]} />)
expect(screen.getByText(/test/i))
})
It fails because my text is never passed properly as a prop, this is the result:
<body>
<div>
<div
class="TextWithIcons__TextWithIconsContainers-sc-1qor9wr-0 cgvqRu"
data-cy="customFields_TextWithIcons_TextWithIconsContainers"
>
<div
class="FlexBox__Box-sc-mvbcpv-0 FlexBox__Flex-sc-mvbcpv-1 TextWithIcons__IconsListContainer-sc-1qor9wr-1 CZkHb eVEBgh jMQLdb"
data-cy="customFields_TextWithIcons_IconsListContainer"
/>
<div
data-cy="wrappedEllipsis_WrappedEllipsis_div"
style="width: 100%; position: relative;"
>
<div
data-cy="__mocks___react-tippy_div"
/>
</div>
</div>
</div>
</body>
The wrapped_ellipses comes from the rendering of the <TextField />
so that's clearly working. And again, the component <TextWithIcons cellText={'test'} iconList={[]} />
renders correctly in the client so I'm not sure what's going on.