我在Ruby项目中使用带有react_on_rails gem的React 一切正常,但是当我启动Jest测试时,会出现此错误:
/Users/alexandar/projects/ezeewallet.com/app/javascript/bundles/DatePicker/DatePickerRange.jsx:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import PropTypes from 'prop-types';
^^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:80:7)
at Object.<anonymous> (spec/javascripts/member/DatePicker.spec.js:15:24)
package.json:
"devDependencies": {
"add": "^2.0.6",
"babel-core": "^6.26.3",
"babel-eslint": "^8.0.2",
"babel-jest": "^23.6.0",
"babel-plugin-module-resolver": "^3.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"clean-webpack-plugin": "^1.0.0",
},
....
.babelcr:
{
"presets": [["env", {"modules": false}], "react"],
"env": {
"test": {
"presets": [["env"], "react"]
}
},
"plugins": [
["module-resolver", {"root": ["./app/javascript"], "alias": {}}],
"syntax-dynamic-import",
"transform-object-rest-spread",
["transform-class-properties", {"spec": true}]
]
}
我想念什么吗?
关于, 亚历克斯
答案 0 :(得分:1)
IV忘记在json包中为jsx文件添加x:
"jest": { "transform": { "^.+\\.jsx?$": "babel-jest" }
现在一切都很好