gpt4 book ai didi

reactjs - Jest 测试 Babel 错误 : Plugin/Preset files are not allowed to export objects

转载 作者:行者123 更新时间:2023-12-03 13:15:12 29 4
gpt4 key购买 nike

我正在使用非常最新的(2017 年 12 月) 依赖项堆栈。当我使用 Jest 尝试同构 react 测试时,测试套件不断失败并出现以下错误:

* Test suite failed to run
[BABEL] /__tests__/router.test.js: Plugin/Preset files are not allowed to
export objects, only functions.

这是我的依赖项:

"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"
}

.babelrc:

{
"presets": [
"env",
"react",
]
}

有人知道为什么 Jest 不会运行吗?

最佳答案

{
"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.

关于reactjs - Jest 测试 Babel 错误 : Plugin/Preset files are not allowed to export objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47878222/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com