我使用的是最新的(2017年12月)依赖项堆栈。当我尝试使用Jest进行同构反应测试时,测试套装会因以下错误而失败:
"dependencies": {
"axios": "^0.17.1",
"babel-polyfill": "^6.26.0",
"cors": "^2.8.4",
"express": "^4.16.2",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.35",
"babel-cli": "^6.26.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.0.2",
"babel-jest": "^22.0.1",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"enzyme": "^3.2.0",
"enzyme-adapter-react-16": "^1.1.0",
"enzyme-to-json": "^3.2.2",
"eslint": "^4.11.0",
"eslint-plugin-react": "^7.5.1",
"html-webpack-plugin": "^2.30.1",
"jest": "^21.2.1",
"nodemon": "^1.11.0",
"parallelshell": "^3.0.2",
"react-test-renderer": "^16.2.0",
"regenerator-runtime": "^0.11.1",
"supertest": "^3.0.0",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4"
},
"peerDependencies": {
"babel-core": "^7.0.0-0"
}
以下是我的依赖项:
{
"presets": [
"env",
"react",
]
}
.babelrc:
skimage.io.imread
有没有人对Jest为什么不会跑步有任何见解?
答案 0 :(得分:5)
babel bridge旨在涵盖6到7之间的任何问题
这不是桥接包的100%。它所做的就是允许使用if($('.parent div').length > 0)
$('.parent').show();
else
$('.parent').hide();
的工具传递给babel-core
。整个包裹是this single line of code。
如果您使用的是@babel/core
,则需要使用适用于Babel 7的插件。这意味着@babel/core
应更改为babel-preset-react
,@babel/preset-react
和@babel/preset-env
相同.babelrc
应该是:
{
"presets": [
"@babel/env",
"@babel/react",
]
}
同样,babel-polyfill
应为@babel/polyfill
。
这些都没有得到很好的记录,因为Babel 7仍然是一个不稳定的测试版。
答案 1 :(得分:4)
{
"presets": [
"env",
"react"
],
"test": [
"jest"
]
}
为您添加“ test”的最后一个代码块babel.rc 这是我的.babelrc代码供参考
{
"presets": [
"env",
"react"
],
"plugins": [
"transform-class-properties",
"transform-object-rest-spread"
],
"test": [
"jest"
]
}
这是我在命令行中的输出
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 9.264s
Ran all test suites.
Done in 12.99s.
答案 2 :(得分:0)
在配置
jest
与babel-6
时,我遇到了同样的挑战。
但总而言之,这种--devDependencies
的组合对我有用,我设置了babel-jest
来转换我的**.js
文件:
// package.json
"devDependencies": {
"babel-core": "6.26.0",
"babel-jest": "21.2.0",
"babel-loader": "7.1.2",
"babel-preset-env": "1.6.0",
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "6.24.1",
"jest": "21.2.1",
"webpack": "3.6.0"
},
"jest": {
"transform": {
"^.+\\.jsx?$": "babel-jest"
}
}
// .babelrc
{
"presets": [
"env",
"stage-0",
"react"
]
}