question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StoryShots "default" test fails to run for new React project

See original GitHub issue

Describe 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:

  1. In an empty directory, run yarn init, with default options.
  2. Run npx -p @storybook/cli sb init.
  3. Say that you want to manually choose a Storybook project type, and select React.
  4. Enter yarn run storybook or npm run storybook. Either should be successful, and open the demo storybook page in a browser.
  5. Run npm i -D @storybook/addon-storyshots
  6. Run npm i jest
  7. Add jest to scripts section in package.json (see ‘Code snippets’ section for full package.json contents).
  8. Create a file called ‘storyshots.test.js’ in the root directory.
  9. Make its contents match the provided test code from the URL above (see code snippets section for exact code block).
  10. Run yarn test or npm run test.
  11. 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:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jerlam06commented, Jul 10, 2019

I have got the very same issue.

0reactions
danbambercommented, Jul 2, 2020

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:

{
    "presets": ["@babel/preset-env", "@babel/preset-react"]
}

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found