获取语法错误:名称参数不是有效的自定义元素名称
我正在尝试使用 Enzyme 和 Jest 对我的 React 应用程序进行单元测试,但收到此错误
` FAIL src/components/XYZ/tests/ABC.test.js
● 测试套件无法运行
SyntaxError: Name argument is not a valid custom element name.
测试套件: 2 次失败,共 2 次 测试:总共 0 次 快照: 共 0 个 时间:3.224秒 运行所有测试套件。`
我的 Jest 配置文件如下
"jest": {
"moduleNameMapper": {
"d3": "<rootDir>/node_modules/d3/dist/d3.min.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"^.+\\.(css|less|scss)$": "identity-obj-proxy"
},
"setupFiles": [
"./src/"
],
"setupFilesAfterEnv": [
"./src/setUpTests.js"
],
"testPathIgnorePatterns": [
"./node_modules/"
]
},
请让我知道我在这里做错了什么? TIA
I am trying to do unit testing of my React app using Enzyme with Jest but getting this error
` FAIL src/components/XYZ/tests/ABC.test.js
● Test suite failed to run
SyntaxError: Name argument is not a valid custom element name.
Test Suites: 2 failed, 2 total
Tests: 0 total
Snapshots: 0 total
Time: 3.224 s
Ran all test suites.`
My Jest Config file is as following
"jest": {
"moduleNameMapper": {
"d3": "<rootDir>/node_modules/d3/dist/d3.min.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)quot;: "<rootDir>/__mocks__/fileMock.js",
"^.+\\.(css|less|scss)quot;: "identity-obj-proxy"
},
"setupFiles": [
"./src/"
],
"setupFilesAfterEnv": [
"./src/setUpTests.js"
],
"testPathIgnorePatterns": [
"./node_modules/"
]
},
Please let me know what I am doing wrong here ? TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这里用于 setupFiles 的配置是错误的。根据笑话文档
https://jestjs.io/docs/configuration#setupfiles-array
setUpFiles 用于“运行一些代码来配置或设置测试环境的模块的路径列表。每个 setupFile 将在每个测试文件中运行一次。由于每个测试都在其自己的环境中运行,因此这些脚本将在这在执行 setupFilesAfterEnv 之前和测试代码本身之前测试环境“
请删除 setUpFiles 或在此处使用正确的文件路径。
I think the configuration used for setupFiles is wrong here. As per jest documentation
https://jestjs.io/docs/configuration#setupfiles-array
setUpFiles is used for "A list of paths to modules that run some code to configure or set up the testing environment. Each setupFile will be run once per test file. Since every test runs in its own environment, these scripts will be executed in the testing environment before executing setupFilesAfterEnv and before the test code itself. "
Please either remove setUpFiles or use proper file path here .