Vue.js 将Jest与Vue一起使用时,Jest似乎被.Vue文件中的HTML注释卡住了
下面是我运行Jest时看到的输出:Vue.js 将Jest与Vue一起使用时,Jest似乎被.Vue文件中的HTML注释卡住了,vue.js,jestjs,Vue.js,Jestjs,下面是我运行Jest时看到的输出: ● Test suite failed to run /home/ubuntu/chat-app/frontend/node_modules/@babel/runtime-corejs2/helpers/esm/asyncToGenerator.js:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest
● Test suite failed to run
/home/ubuntu/chat-app/frontend/node_modules/@babel/runtime-corejs2/helpers/esm/asyncToGenerator.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import _Promise from "../../core-js/promise";
^^^^^^^^
SyntaxError: Unexpected identifier
11 | {{ current_nickname }}
12 |
> 13 | <!-- https://linearicons.com/free#cdn -->
| ^
14 | <span class="lnr-button">
15 | <svg class="lnr lnr-pencil" @click="prompt_nickname()"><use xlink:href="#lnr-pencil" /></svg>
16 | </span>
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at src/components/ChatApp.vue:13:49
at Object.<anonymous> (src/components/ChatApp.vue:219:3)
jest.config.js
:
module.exports = {
presets: [
'@vue/app'
]
}
module.exports = {
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
transform: {
'^.+\\.vue$': '<rootDir>/node_modules/vue-jest',
'.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$':
'jest-transform-stub',
'^.+\\.(js|jsx)?$': '<rootDir>/node_modules/babel-jest'
},
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
snapshotSerializers: ['jest-serializer-vue'],
transformIgnorePatterns: ['<rootDir>/node_modules/']
};
module.exports={
moduleFileExtensions:['js','jsx','json','vue'],
转换:{
“^.+\\.vue$”:“/node\u modules/vue jest”,
“.+\(css | styl | less | sass | scss | png | jpg | ttf | woff | woff2)$”:
“jest transform存根”,
“^.+\\(js | jsx)?$”:“/node\u modules/babel jest”
},
模块映射:{
“^@/(.*)$”:“/src/$1”
},
快照序列化程序:['jest-serializer-vue'],
transformIgnorePatterns:['/node_modules/']
};
不确定问题是什么,谢谢您的帮助。我也遇到了同样的错误,我的情况唯一不同的是1。我正在使用
transformIgnorePatterns
和2。我使用bable preset作为“@babel/preset env”
,即使我在要测试的组件中使用子组件时也有相同的错误。有人找到解决这个问题的线索吗?如果是,请分享消除此错误的步骤。