Storybook ❤️ Testing Library
Reuse stories in unit tests
You have to render a component in isolation to test it. But components can be tough to isolate because they’re connected to data, state, hooks and API calls.
Storybook makes it easy to isolate components for development. You can mock providers and API calls. Or use addons to provide data, static assets and theming context.
We’re excited to launch @storybook/testing-react to help you reuse your stories in Testing Library, Jest and Enzyme. All the setup you’ve done in Storybook to isolate the component is reused in tests.
- Write test cases once as “stories”.
- Use stories to build the component in Storybook
- Reuse stories in your unit testing setup.
Testing-Library is now the go-to tool for testing component interactions. It’s lightweight and provides utilities that mimic real-world usage. Here are a few helpful resources to get you started:
- The Intro to Storybook guide shows you how to write Unit tests with React Testing Library
- How to use stories with Testing Library (35m video)
- Better testing with Storybook (article)
- Build, test and release a React component library with Storybook (tutorial)
💖 Varun, DX @ Storybook