我按照Jest - React 教程测试了一个 React 组件。
不幸的是,Jest 抛出:
SyntaxError: /Users/mishamoroshko/react-playground/src/search-panel/questions/__tests__/questions-test.js: /Users/mishamoroshko/react-playground/src/search-panel/questions/questions.js: Unexpected token ILLEGAL
at Contextify.sandbox.run (/Users/mishamoroshko/react-playground/node_modules/jest-cli/node_modules/jsdom/node_modules/contextify/lib/contextify.js:12:24)
at JSDomEnvironment.runSourceText (/Users/mishamoroshko/react-playground/node_modules/jest-cli/src/JSDomEnvironment.js:108:22)
at Object.runContentWithLocalBindings (/Users/mishamoroshko/react-playground/node_modules/jest-cli/src/lib/utils.js:341:23)
重现:
git clone git@github.com:SEEK-Jobs/react-playground.git
cd react-playground
npm install
npm test
有任何想法吗?
更新 1:
我想知道问题是否在于 Jest 不了解 ES6,我需要使用6to5-jest
.
有没有办法指定 2 个预处理器package.json
?
"jest": {
"rootDir": "src",
"scriptPreprocessor": "../preprocessor.js",
"unmockedModulePathPatterns": [
"../node_modules/react"
]
}