【发布时间】:2018-08-31 19:24:14
【问题描述】:
开箱即用的 create-react-app with jest 总是失败
我做的步骤
create-react-app cra-test
cd cra-test
yarn install
把原来package.json中的test改成这个
{
"name": "cra-test",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "1.1.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject"
}
}
当我运行yarn test 时,测试失败了。这是输出
yarn run v1.1.0
$ jest
FAIL src\App.test.js
● Test suite failed to run
.../cra-test/src/App.test.js: Unexpected token (7:18)
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
> 7 | ReactDOM.render(<App />, div);
| ^
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 3.413s, estimated 12s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我读到这可能是由于升级 Jest 导致它与 create-react-app 不兼容,但我没有这样做。
node --version && yarn --version && npm --version && create-react-app --version
v6.10.2
1.1.0
5.7.1
1.4.3
【问题讨论】:
-
为什么要更改原来的测试?
-
我同意@VivekN,只需创建应用程序,运行测试脚本即可 100% 工作。它还使用 Jest 进行测试。我对您要完成的工作感到困惑。
标签: node.js reactjs jestjs create-react-app yarnpkg