-
Notifications
You must be signed in to change notification settings - Fork 50
storyshots
Nelson Omuto edited this page Jul 16, 2018
·
5 revisions
Storyshots offer another avenue for testing components similar to jest snapshots. Read more here https://storybook.js.org/testing/structural-testing/
The getting started does not fully explain all the steps required so I will highlight things that may cause the setup to fail.
First step is make sure you have the following deps installed:
"@storybook/addon-storyshots": "^3.4.8",
"babel-plugin-require-context-hook": "^1.0.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
In your jest config main file import the require context hook and invoke it
import registerRequireContextHook from 'babel-plugin-require-context-hook/register';
registerRequireContextHook(); // required for storyshots to use webpack require.context
Ensure your babelrc test env looks like this (see test config):
"env": {
"development": {
"plugins": [
"react-hot-loader/babel"
]
},
"test": {
"presets":[
["env", { "modules": false }],
"react"
],
"plugins": [
"transform-es2015-modules-commonjs",
"dynamic-import-node",
"require-context-hook",
"transform-class-properties"
]
}
}
- Make sure you pass a configPath pointing to your storybook config directory
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots({
configPath: '.tooling/storybook'
});
npm test
- Upon running your jest tests you should now see storyshots generated.
npm test -- -u
will update snapshots