【发布时间】:2017-12-28 01:06:04
【问题描述】:
我知道这可能以前已经发布过,但我真的很困惑为什么我的测试在我的 React 项目中不起作用。这是我的.babelrc 文件:
{
"presets": ["react", "es2015", "stage-0"],
"plugins": [
"transform-runtime",
"add-module-exports",
"transform-decorators-legacy"
],
"env": {
"development": {
"plugins": [
"typecheck",
["react-transform", {
"transforms": [{
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}]
}]
]
},
"test": {
"presets": ["es2015", "react", "stage-0"],
"plugins": [
"transform-runtime",
"add-module-exports",
"transform-decorators-legacy"
]
}
}
}
这是我在 package.json 中的 Jest 设置
"jest": {
"moduleFileExtensions": [
"js",
"jsx",
"json"
],
"moduleNameMapper": {
"ExampleTest": "<rootDir>/app/pages/ExampleTest.js"
},
"moduleDirectories": [
"app",
"node_modules"
]
},
我得到的错误是Test suite failed to run... SyntaxError: Unexpected token <。
据我所知,它试图运行的文件中包含 JSX/ES6 代码……它不知道如何转换它?这很奇怪,因为我已经在 .babelrc 中告诉它这样做。我还为 Jest 提供了适当的 moduleDirectories。
任何帮助将不胜感激。
【问题讨论】:
标签: javascript reactjs testing babeljs jestjs