Storybook’s Visual Tests addon enters beta
Tags: testing, qa, visualtesting, javascript
Published: 2024-02-15 15:48:59

[Storybook 8](https://storybook.js.org/blog/storybook-8-beta/?ref=storybookblog.ghost.io) introduces a totally new workflow for safeguarding your UI from unexpected visual changes, via **the Visual Tests addon**. Learn how it works and try the beta today.

## What is visual testing?

The challenge of UI testing is that functional tests don’t give you the complete picture of how your UI works. For example, testing a login button might confirm the button’s logic but it won’t detect that the button is now completely covered by the nav bar. It’s functional for your test, but not for your users.

You can solve this problem by using visual testing tools. When you introduce a code change, they visually diff image snapshots of your components to previous baseline versions. Then, you can either fix issues before merging to the main branch, or accept the changes and set new baselines for future tests. When combined with functional tests, this gives the best of both worlds: complete confidence that your app looks and works correctly.

Historically, visual testing takes place in CI as part of your PR review process. It’s so effective that we even built a cloud service called Chromatic that is used across the industry to automatically turn stories into visual tests.

The Visual Tests addon for Storybook brings a totally new approach, where you can now get visual diffs in Storybook at any stage of development. No need to wait on CI to confirm visual fidelity.

## Get started

### Install

You’ll need to be using the Storybook 8 beta to use the Visual Tests addon. If you initialize a new project in Storybook 8 using `npx storybook@next init`, the addon will be installed automatically. If you upgrade an existing project using `npx storybook@next upgrade`, you’ll need to manually add the addon using `npx storybook@next add @chromatic-com/storybook`.

[Learn more about setup in the docs](https://storybook.js.org/docs/8.0/writing-tests/visual-testing)

### Workflow

Once setup is complete, when you next load Storybook, you’ll see a new addon panel for Visual Tests. You can run your first test by clicking the ▶️ button in the Storybook sidebar:

![VT addon, run tests](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ph6ofjl25n650vufygs8.png)

Then, after running tests, you can view and inspect diffs in the Storybook addon panel:

![VT addon, diffs in Storybook](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9d560zelrshruakft8l.png)

If the changes are intentional, accept them to set new baselines. If not, fix the detected changes, then restart the process.

![VT addon, accept new baselines](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4l1owv48pp2unvptuxmf.png)

## **High fidelity, high performance**

Chromatic is by far the fastest visual testing tool on the market, capable of processing thousands of stories per minute. But what’s fast in CI can feel slow in an interactive UI. So, as part of this addon’s development, we sped up the workflow by 78%. Faster tests make you more productive.

This aligns with the theme of Storybook 8's improvements: performance. Among many other gains, you can now create 3x faster builds for testing workflows, and we quickened startup time in React projects by 20-40%.

Finally, we created a beautiful addon UX. You can view the test status of your stories in the Storybook sidebar, which highlights stories needing your attention in yellow. You can also filter the sidebar to only show stories containing changes.

![VT addon, sidebar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lptiaonckbr28eosbrw1.png)

## Share your feedback

The Visual Tests addon is in public beta and is being actively used by projects of all shapes and sizes. We’d love your feedback to help get it ready for a first stable release as part of Storybook 8.0 and Chromatic 3.0.

Share any issues you encounter using Visual Tests addon with [the Storybook and Chromatic team](mailto:support@chromatic.com).