-
Notifications
You must be signed in to change notification settings - Fork 24
Documentation suggests using es6 in jest's setupFiles.js #15
Comments
Hey @radfahrer thanks for opening this issue and for using this library! Could you make a reproduction repo? I have tested out in CRA and non-CRA projects and they worked well. I assume you have worked around it by using |
Hello @radfahrer good issue indeed, What versions of |
Actually trying to convert to I ended up abandoning the idea of global decorators for the time being. Our project doesn't currently have any but we are using |
node 14 and storybook 6 |
I ran into this same problem. I am using I am not using babel or webpack explicitly and I am using Typescript and ts-jest and I ran into the same issue. I got around it by converting my setupTest.js file to a setupTest.ts file and converting my preview.js to preview.tsx (I was importing a wrapping React component) I don't have time to setup a reproduction example but hopefully this comment helps someone else who ends up here from Google. |
I'm also running into this issue, and the last suggestion here didn't change anything for me since I was already doing it, but I thought I'd share what helped me for anyone who may have the same issue as me. The file that seemed to be causing the issue for me is |
Hi, I've tried this and I get same issue but it's due to the decorators for some reason. It's with a shiny new setup: The error I get is: ^
and this is using the example decorator from this repo? Would like to use this addon but not sure if its viable atm looking at it with fresh eyes, its possibly my setup that needs tweaking |
I had a But for now THIS particular error (SyntaxError: Cannot use import statement outside a module) is gone. The trick it seems is to let Babel do the transpiling. The preset here at work is the
module.exports = {
presets: [
['@babel/preset-env', { targets: 'defaults' }],
'@babel/preset-react',
'@babel/preset-typescript'
]
};
const { setGlobalConfig } = require('@storybook/testing-react');
const globalStorybookConfig = require('../.storybook/preview'); // path of your preview.js file
setGlobalConfig(globalStorybookConfig); Update, it's working with Global Decorators! |
Hey there! I wanted to thank you for using @storybook/testing-react!
Please do the following:
// Component.test.jsx
- import { composeStories } from '@storybook/testing-react';
+ import { composeStories } from '@storybook/react';
// setup-files.js
- import { setProjectAnnotations } from '@storybook/testing-react';
+ import { setProjectAnnotations } from '@storybook/react'; For now, I'll be closing this issue. Please, if even after migrating, you are still experiencing issues, report them in the Storybook monorepo. Thank you so much for this journey! |
Describe the bug
Reading the documentation for global decorators here: https://storybook.js.org/addons/@storybook/react-testing
It says to import storybook/preview.js
Import is an es6 feature as is the component story format which is the recommended way to implement preview.js
However, Jest doesn't transpile the setupFiles.js file when starting up: jestjs/jest#9041
This causes errors when trying to run tests:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Tests should run and
composeStory
should work.The text was updated successfully, but these errors were encountered: