gpt4 book ai didi

reactjs - Jest 错误 - 测试套件运行失败 - 未知选项 : . 预设

转载 作者:行者123 更新时间:2023-12-05 06:17:37 28 4
gpt4 key购买 nike

错误描述:当为 javascript 代码的简单单元测试运行 jest 时,出现错误测试套件无法运行未知选项:.preset

以下是重现错误的文件:

    {
"name": "RelocationTrackerApp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest",
"start-debug": "webpack-dev-server --open --config webpack.dev.js",
"build-release": "webpack --config webpack.prod.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/preset-react": "^7.9.4",
"@testing-library/react": "^10.0.3",
"babel-jest": "^25.5.1",
"babel-loader": "^8.1.0",
"jest": "^25.5.0",
"react-test-renderer": "^16.13.1",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3",
"webpack-merge": "^4.2.2"
},
"dependencies": {
"react": "^16.13.1",
"react-bootstrap": "^1.0.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2"
}
}

.babelrc

{ "preset": ["@babel/preset-env", "@babel/preset-react"] }

sum.test.js

    const sum = require('./sum');

test('properly ads two numbers', () => {
expect(sum(1, 2)).toBe(3)
})

下面是实际的错误:测试套件运行失败

Unknown option: .preset. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options.

at throwUnknownError (node_modules/@babel/core/lib/config/validation/options.js:123:27)
at node_modules/@babel/core/lib/config/validation/options.js:108:5
at Array.forEach (<anonymous>)
at validateNested (node_modules/@babel/core/lib/config/validation/options.js:84:21)
at validate (node_modules/@babel/core/lib/config/validation/options.js:75:10)
at node_modules/@babel/core/lib/config/config-chain.js:174:34
at cachedFunction (node_modules/@babel/core/lib/config/caching.js:62:27)
at cachedFunction.next (<anonymous>)
at evaluateSync (node_modules/gensync/index.js:244:28)
at sync (node_modules/gensync/index.js:84:14)

*****如果这意味着什么,我正在使用 webpacks 作为打包工具**

最佳答案

我认为这是因为它是 presets 而不是 preset 在你的 .babelrc 中。

顺便说一句,未知选项不是.preset,而是preset。错误消息以某种方式在未知标记之前和之后添加了一个点,因此它显示 .preset. 表示它实际上不理解 preset

关于reactjs - Jest 错误 - 测试套件运行失败 - 未知选项 : . 预设,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61550023/

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