DEV Community

Discussion on: Don't snapshot your UI components, make assertions!

Collapse
 
vladutzik profile image
Vladimir Tribusean

Totally agree.
You usually write tests to be sure that your code changes are not breaking stuff and only changes the components you want.

Imagine you're working on a project along with another 40 small teams. You use some shared components, and you make the change in a shared component, some other teams are not expecting neither functional nor visual changes to component.

As to use your example. You have a card with image and text, you're using this component for listing of blog posts and you expect it to have a link so that clicking on it will lead to a blog post. Other team is using the same component to render the header of blog post on mobile view, with the same image and title, and they expect no link there. Here's where snapshot testing will help you out.

Also using your example, I'd say it makes more sense to have a new component that would be clickableCard or cardWithLink so that you don't change nor add functionality to a visual component.