Storybook + Tests = Forced Isolation as a System
A great tool that connects designers with developers and testers—and even lets the project manager poke around the interface.
Wrapping up the practical side, let's talk testing. Buckle up!
Redesign iterations were killing the frontend on a project (where our team lead, a couple of fullstack JS devs, and PM/QA worked). Storybook saved it.
1. Storybook Sets Rules. Tests Enforce Them.
1.1 Development Without Isolation:
The test fails not because of a button bug. It fails because of a system bug.
1.2 Development With Storybook:
In Storybook, the component lives alone or with explicitly specified dependencies.
This isn't just a feature. It's an architectural constraint.
1.3 Testing Difference on a Button Example:
In summary, we used to test a system of 156 UI components with Jest tests that overlapped. Now, by breaking components into simple units and following Storybook rules, we test each system element/unit, covering everything without overlaps or gaps.
2. "Why Tests If Storybook Has Actions?"
2.1 Great question. But Actions ≠ Tests.
After setting up (and keeping current) your UI components in Storybook - that's real work! - you can open the Actions tab for each. With predefined interactions (e.g., button clicks, inputs) coded in .storybook files that auto-load into the UI, you just log what you're tracking/handling.
Actions in Storybook:
Tests:
Actions demonstrate behavior. Tests guarantee correctness.
Actions show a green check. Tests show a red X if broken.
2.2 One System. Two Roles: Demo and Verification
You end up with a system that describes expected UI interactions in Storybook - like explicitly marking a button as clickable. This serves as a checklist for tests.
Devs follow the demo (expected interaction) to write tests. Actions show, tests verify.
3. What Does This Give You?
For testing purposes:
- Tests don't fail due to neighboring components.
- Each test checks one thing.
- All states and interactions are already in stories.
For refactoring purposes:
- Change implementation → stories stay the same.
- Storybook shows: looks right per design.
- Tests confirm: works as expected internally.
4. Why It Works
4.1 Default Decomposition (Storybook forces us to divide into units)
Storybook forces unit breakdown. Can't make a complex story → can't make a complex component
4.2 Explicit Dependencies (Storybook explicitly lists style dependencies and variants)
ThemeProvider needed? It's in the story. Not specified? Not needed. Styles and variants are explicit
4.3 Actions for Visual Demo, Tests for Guarantees
5. Rules
- No component in Storybook → no component in code.
- No state in Storybook → no state in component.
- No test on story → state doesn't exist.
6. Bottom Line
Storybook is a forced isolation system.
Isolated component:
- Easy to test
- Easy to change
- Easy to delete
Non-isolated component = technical debt.
You're already testing the system - not just the button, but every Storybook variant. Every state. Every prop. That's the system.