StoryShots "default" test fails to run for new React project
See original GitHub issueDescribe the bug
Trying to run the provided test on the structural testing page of the storybook website (https://storybook.js.org/testing/structural-testing/) fails with the error
SyntaxError: Unexpected identifier
pointing at
initStoryshots
To Reproduce Steps to reproduce the behavior:
- In an empty directory, run
yarn init
, with default options. - Run
npx -p @storybook/cli sb init
. - Say that you want to manually choose a Storybook project type, and select React.
- Enter
yarn run storybook
ornpm run storybook
. Either should be successful, and open the demo storybook page in a browser. - Run
npm i -D @storybook/addon-storyshots
- Run
npm i jest
- Add
jest
to scripts section inpackage.json
(see ‘Code snippets’ section for fullpackage.json
contents). - Create a file called ‘storyshots.test.js’ in the root directory.
- Make its contents match the provided test code from the URL above (see code snippets section for exact code block).
- Run
yarn test
ornpm run test
. - Error shown.
Expected behavior
storyshots.test.js
to pass.
Screenshots
Code snippets
Contents of package.json
:
{
"name": "temp",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"jest": "^24.1.0"
},
"devDependencies": {
"@babel/core": "^7.2.2",
"@storybook/addon-actions": "^4.1.11",
"@storybook/addon-links": "^4.1.11",
"@storybook/addon-storyshots": "^4.1.11",
"@storybook/addons": "^4.1.11",
"@storybook/react": "^4.1.11",
"babel-loader": "^8.0.5"
},
"scripts": {
"test": "jest",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
}
}
Contents of storyshots.test.js
:
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots({ /* configuration options */ });
System:
- OS: Ubuntu MATE 18.10
- Version: See “Code snippets” section for versions.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
StoryShots "default" test fails to run for new React project #5575
Run npx -p @storybook/cli sb init . Say that you want to manually choose a Storybook project type, and select React. Enter yarn...
Read more >3 - Stack Overflow
I want to combine storybooks and jest snapshot testing, but I don't get it working. As soon as I follow the doc and...
Read more >Snapshot tests - Storybook
Storyshots is the official Storybook addon that enables snapshot testing, powered by Jest. Run the following command to install Storyshots: YARN; NPM.
Read more >How to simplify component testing with React Storybook
First, we'll bootstrap a new React project. ... Storybook's testing page should start on the local address http://localhost:6006/ in our ...
Read more >Testing Overview - React
You can test React components similar to testing other JavaScript code. ... Running a complete app in a realistic browser environment (also known...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have got the very same issue.
After trying upgrading Storybook, downgrading Jest and a few other things. I found adding a .babelrc file to the root of my project with this inside fixed it for me:
I believe this is needed for Jest to work with Storyshot. I’m not using Create React App so that’s probably why most people aren’t having this issue. Hope this helps someone