When should we use Storyshots? #18119
-
Even though the Storyshots add-on exists, which allows you to import stories into Jest, it isn't what's documented on various blog posts around Storybook testing / integration with Jest, like: https://medium.com/storybookjs/testing-lib-storybook-react-8c36716fab86 and https://storybook.js.org/blog/interaction-testing-with-storybook/ We just implemented Storyshots after finding that add-on via Google searching, but now that we've discovered these other blog posts with completely separate approaches, we're wondering if we should switch. Could someone explain when to use one vs. the other, and the trade-offs of each? And could this be documented? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Great question. We've recently introduced new testing mechanisms in Storybook and things are still in flux, but let me do my best to break things down. cc @yannbf Storyshots was the original testing tool for Storybook. It was dead simple to set up and you got DOM snapshots for free for all your stories. Unfortunately, there were a bunch of things wrong with its architecture/implementation. Nevertheless it's been the only game in town for awhile so it's widely used. Test runner is intended to be the primary "new way" to test stories. We just released the first version, so three is still some work to do to create a direct upgrade path from Storyshots. In the meantime, you can get smoke tests for all your stories, and also write interaction tests on top of stories when you need them. testing-react is a secondary "new way" to test stories. It's really just a way to make stories more portable to re-use in tests, and it means that you can write whatever arbitrary setup & teardown code you want in whatever testing tool you choose. In some sense it's a more flexible escape hatch for the test runner. I would recommend using the test runner. You should be able to get 80% of the value of Storyshots today. With any luck we'll release some enhancements to give you the other 20% (should you need it) in the next couple months. We'll also be documenting all this better as the picture takes shape. In the meantime @winkerVSbecks has recently updated the Testing handbook with the current best practices. |
Beta Was this translation helpful? Give feedback.
-
Ok, thanks for answering. One thing: with the way that the Test Runner is set up, it looks like Jest is run using
testMatch: [
'**/__tests__/*.+(ts|js)',
'**/*.test.(ts|tsx|js)',
'<rootDir>/storyshots/index.ts'
], And then I just run Jest tests normally. But it's unclear how the Test Runner integrates with Jest config. How do you run Jest regular tests vs test coverage tests using |
Beta Was this translation helpful? Give feedback.
Great question. We've recently introduced new testing mechanisms in Storybook and things are still in flux, but let me do my best to break things down. cc @yannbf
Storyshots was the original testing tool for Storybook. It was dead simple to set up and you got DOM snapshots for free for all your stories. Unfortunately, there were a bunch of things wrong with its architecture/implementation. Nevertheless it's been the only game in town for awhile so it's widely used.
Test runner is intended to be the primary "new way" to test stories. We just released the first version, so three is still some work to do to create a direct upgrade path from Storyshots. In the meantime, you can get smoke test…