DEV Community

sanjeeviraj RC
sanjeeviraj RC

Posted on

what things should be covered with unit test for a react application?

I am working on slightly large react application, currently there is only few test-cases covered with basic assertion like 'text' exists/not exits.

Planning to cover all the Components with meaningful unit-tests, have started to use testing-library with jest.

what questions should be addressed by our self while writing test-cases for a component in react, specifically in React-testing-library ? any generic ui unit testing pattern would help.

Top comments (1)

Collapse
 
v0idzz profile image
Piotr Romanowski

When writing unit tests for components I usually ask myself "How would a typical user interact with this component?". This helps me come up with a couple of test cases quickly. Remember to not overdo unit tests, though. They are not a perfect solution and there's a big chance you'll be writing useless tests that will only verify if your mocks are working correctly.