r/reactjs • u/kylegach • Jun 20 '24
Resource Visual testing is the greatest trick in UI development
https://storybook.js.org/blog/visual-testing-is-the-greatest-trick-in-ui-development/12
u/ForeverAWhiteBelt Jun 20 '24
Visual testing usually fails tests even if minor things like text changes tho, correct?
8
u/FURyannnn Jun 21 '24
Yeah, that's precisely the point of them though - to ensure that caught changes are intentional. It does definitely involve more manual work for the engineer but can prevent bugs and regressions
3
u/kylegach Jun 21 '24
Additionally, for something like a page with primarily content, you can ignore the headings and main content, so that changes there are ignored. (Of course, you should have those text styles tested elsewhere, in isolation!)
And speaking of isolation, that's really the key: by isolating a component's dependencies (context, network requests, other data sources, etc.), you ensure that visual tests are truly testing your UI and not the environment in which they're rendered.
1
u/NescafeAtDayLight Jun 21 '24
Will 1-2px change of a component fail the test? How wouod someone implement a visual test
2
u/kylegach Jun 21 '24
Yes, it would (unless you have your diff threshold set really low, but that causes lots of false positives).
If you're using the Visual Tests addon like in the post, your Storybook stories automatically become visual tests (you can opt-out any stories that shouldn't be visually tested).
1
u/gregberge Jul 28 '24
Visual testing is indeed a powerful approach in UI development, and the blog post from Storybook does a great job of highlighting its benefits. It's amazing how visual testing can catch UI bugs that might slip through other forms of testing.
If you're exploring options beyond Chromatic, consider trying Argos. Argos is an open-source visual regression testing tool that integrates seamlessly with your CI pipeline and offers robust features for ensuring UI consistency. It's highly customizable, making it a versatile choice for any development team.
While Chromatic is excellent, Argos provides a cost-effective alternative without compromising on functionality. It’s a great way to maintain high-quality UIs while managing your budget effectively.
Check out Argos and see how it can complement your visual testing strategy!
1
10
u/kylegach Jun 20 '24
TL;DR:
What are visual tests?
A visual test is a snapshot test that compares image snapshots of a UI component before and after a code change. The test fails if the snapshots do not match.
How are they better than unit tests for UI?
Less code, more useful results
Why should I bring them into my workflow?
Work faster and with more confidence
What is the best way to visual test my components?
The Visual Tests addon for Storybook