Reactjs 如何调试React jest酶测试用例

Reactjs 如何调试React jest酶测试用例,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,当我试图调试终端中的Rect Jest酶测试用例时,我遇到了以下错误,并因此被卡住 我使用create react app创建了应用程序,以下是我的配置: .babelrc { “环境”:{ “测试”:{ “源地图”:“内联”, “预设”:[“es2015”,“反应应用程序”], “插件”:[“转换导出扩展”], “仅限”:[ “/***.js”, “节点\u模块/jest运行时” ] } } } 来自package.json的Jest配置 “开玩笑”:{ “测试匹配”:[ “***/src/

当我试图调试终端中的Rect Jest酶测试用例时,我遇到了以下错误,并因此被卡住

我使用create react app创建了应用程序,以下是我的配置:

.babelrc

{
“环境”:{
“测试”:{
“源地图”:“内联”,
“预设”:[“es2015”,“反应应用程序”],
“插件”:[“转换导出扩展”],
“仅限”:[
“/***.js”,
“节点\u模块/jest运行时”
]
}
}
}
来自
package.json的Jest配置

“开玩笑”:{
“测试匹配”:[
“***/src/***/?(*)(规范测试).js?(x)”
],
“快照序列化程序”:[
“酶到json/序列化程序”
],
“ModuleFileXetions”:[
“ts”,
“txx”,
“js”,
“json”
],
“转变”:{
“^.+\\.jsx$”:“巴贝尔玩笑”,
“^.+\\.js$”:“巴别塔笑话”
}
}
测试用例:

import{shall}来自“酶”;
从“./App”导入应用程序;
描述('App',()=>{
它('应该呈现应用',()=>{
常量分量=浅();
expect(component.toMatchSnapshot();
});
});
获取以下错误:

Test suite failed to run

    ReferenceError: [BABEL] .../src/containers/App.spec.js: Unknown option: /node_modules/babel-preset-react-app/index.js.overrides. Check out http://babeljs.io/docs/usage/options/ for more information about options.

    A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

    Invalid:
      `{ presets: [{option: value}] }`
    Valid:
      `{ presets: [['presetName', {option: value}]] }`

    For more detailed information on preset configuration, please see http://babeljs.io/docs/plugins/#pluginpresets-options. (While processing preset: "/node_modules/babel-preset-react-app/index.js")

      at Logger.error (node_modules/babel-core/lib/transformation/file/logger.js:41:11)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:226:20)
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
      at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
          at Array.map (<anonymous>)
      at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
      at OptionManager.mergePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
      at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
      at OptionManager.init (node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
      at File.initOptions (node_modules/babel-core/lib/transformation/file/index.js:212:65)
测试套件无法运行
ReferenceError:[BABEL]…/src/containers/App.spec.js:未知选项:/node\u modules/BABEL预置react App/index.js.overrides。退房http://babeljs.io/docs/usage/options/ 有关选项的详细信息。
此错误的常见原因是存在没有相应预设名称的配置选项对象。例子:
无效:
`{预设:[{选项:值}]}`
有效期:
`{预设:['presetName',{option:value}]}`
有关预设配置的更多详细信息,请参阅http://babeljs.io/docs/plugins/#pluginpresets-选项。(处理预置时:“/node\u modules/babel preset react app/index.js”)
at Logger.error(node_modules/babel core/lib/transformation/file/Logger.js:41:11)
在OptionManager.mergeOptions(node_modules/babel core/lib/transformation/file/options/option manager.js:226:20)
在node_modules/babel core/lib/transformation/file/options/option manager.js:265:14
在node_modules/babel core/lib/transformation/file/options/option manager.js:323:22
在Array.map()处
在OptionManager.resolvePresets(node_modules/babel core/lib/transformation/file/options/option manager.js:275:20)
在OptionManager.mergePresets(node_modules/babel core/lib/transformation/file/options/option manager.js:264:10)
在OptionManager.mergeOptions(node_modules/babel core/lib/transformation/file/options/option manager.js:249:14)
在OptionManager.init(node_modules/babel core/lib/transformation/file/options/option manager.js:368:12)
在File.initOptions(node_modules/babel core/lib/transformation/File/index.js:212:65)
编辑:

在.babelrc中更改“test”-->“dev”后出现上述错误,但得到另一个错误:


“Jest在shall()遇到意外标记”

尝试使用此
.babel
配置:

{
   "presets": ["es2015", "react-app"],
   "plugins": ["transform-export-extensions"],
   "only": [
     "./**/*.js",
     "node_modules/jest-runtime"
   ]
}

这应该会对你有所帮助。

在你的回答中解释为什么这会对他有帮助,以及他引入这一点的错误是什么,这将是很有帮助的problem@EricMajerus在大多数情况下,人们只需要一个有效的解决方案,而不需要繁琐的解释。如果这是问题的作者提出的,那么是的,我会解释这个决定。@SviatKuzhelev,谢谢你的回答,但它没有解决问题。