I have a React component named Product which looks like this:
<div>
<Wrapper>
<Heading>{props.headerText}</Heading>
<Service>({props.items.length})</Service>
</Wrapper>
{props.items !== undefined && props.items.length > 0 ? (
<TableWrapper>
{props.items &&
props.items.length > 0 && (
<DataTable paginationSize={props.paginationSize}>
<DataTable.Heading accessor="name"> Name </DataTable.Heading>
<DataTable.Heading accessor="id"> Service ID </DataTable.Heading>
<DataTable.Heading accessor="type"> Access </DataTable.Heading>
<DataTable.Heading accessor="band"> Band </DataTable.Heading>
<DataTable.Heading accessor="noUsers"> Users </DataTable.Heading>
{props.tableItems.map((p, i) => {
return <DataTable.Row key={i} data={p} />;
})}
</DataTable>
)}
</TableWrapper>
) : (
<NoMessage>{props.noItemMessage}</NoMessage>
)}
</div>
where Wrapper, Heading, Service, TableWrapper are styled-components. I am trying to test this component using Jest and Enzyme to check if the headerText prop is being rendered correctly.The below given code is how I am trying to write my test case:
test("header text is being passed through correctly", () => {
const wrapper = mount(
<Product items={data} headerText="Service" paginationSize="5" noItemMessage="No results found" />
);
expect(wrapper.find(HeaderText).text()).toEqual("Service");
but I get this error as:
TypeError: Cannot read property 'blue' of undefined
at Object.<anonymous>.exports.RightArrow.Icons.RightArrow.extend.props (src/lib/DataTable.js:149:129)
and the line 149 in DataTable.js is:
color: ${props => props.theme.secondary.blue};
I am not able to figure out why I am getting this error. Can anyone please guide me with this issue? I am just trying to check if the headerText is rendered properly from the props.