我正在为一个项目设置Storybook。我遵循了Storybook for React的说明来设置项目。效果很好。然后,我遵循了Structural Testing的说明,并遇到了错误TypeError: require.context is not a function
。
要解决该问题,我在Github上经历了instructions-特别是选项1。这导致了我需要帮助的主要问题。
Details:
/Users/.../___.stories.js:13
(0, _react2.storiesOf)('___/___', module).add('___', () => <_common.Card>
SyntaxError: Unexpected token <
Card
是一个自定义的React组件,可在Storybook页面上使用。如果我将自定义组件替换为标准的div
组件,则同样的问题仍然存在。
任何帮助将不胜感激,很高兴根据需要提供更多信息。
package.json:
"dependencies": {
"babel-plugin-styled-components": "^1.10.6",
"dompurify": "^1.0.11",
"faker": "^4.1.0",
"lodash": "^4.17.15",
"styled-components": "^4.3.2"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@storybook/addon-actions": "^5.1.9",
"@storybook/addon-links": "^5.1.9",
"@storybook/addon-storyshots": "^5.1.10",
"@storybook/addon-storysource": "^5.1.10",
"@storybook/addons": "^5.1.9",
"@storybook/react": "^5.1.9",
"@storybook/storybook-deployer": "^2.8.1",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.6",
"babel-plugin-require-context-hook": "^1.0.0",
"jest": "^24.8.0",
"jest-environment-jsdom-fourteen": "^0.1.0",
"react-test-renderer": "^16.8.6"
},
"jest": {
"testEnvironment": "jest-environment-jsdom-fourteen",
"setupFiles": ["<rootDir>/.jest/register-context.js"]
},
"scripts": {
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"deploy-storybook": "storybook-to-ghpages",
"test": "jest /src"
}
}