Having this component:
import { StyledContainer } from './.styles';
import { MyProps } from './my.types';
export const MyComponent = ({
titleText
}: TitleProps) => {
return (
<StyledContainer>
<h1>
{titleText}
</h1>
</StyledContainer>
);
};
that receives as props:
const mockData = { titleText: <div>My title</div> }; // the props can be React.ReactNode
I want to check if the sent props contains div element so this is the test case:
it('should render component', () => {
render(<MyComponent titleText={mockData.titleText} />);
const titleText = screen.getByRole('heading', { level: 1 });
expect(titleText).toBeDefined();
expect(titleText).toContain('div');
});
The test fails and says:
Expected value: "div"
Received object: <h1><div>My title</div></h1>
is there a way to check if const titleText contains a div HTML tag?