Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
7 replies
venus

Strategy to test components in React

Hey, I am new into testing and I haven't test anything much before. I am still getting stuck about theory what should I test and what shouldn't. For example here.

I have component Heading that takes prop level which is number between 1 and 6.

Is this test useless? And if so, what test would you write for this specific component?

const levels = [1, 2, 3, 4, 5, 6] as const;

it.each(levels)('should rener heading level %s', (level: HeadingLevel) => {
  render(<Heading level={level}>Heading {level}</Heading>);

  expect(screen.getByRole('heading', { level })).toBeInTheDocument();
});
Was this page helpful?