引用vant组件测试报错
测试组件时,报错信息如下:
`[vue-jest]: Less and PostCSS are not currently compiled by vue-jest
FAIL tests/unit/login.spec.js
● Test suite failed to run
/Users/nola/workingSpace/toolBox/back_newwx/node_modules/vant/es/button/style/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/base.css';
^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
9 | :input-lable="$t('user.username')"
10 | :placeholder="$t('user.placeholder.phone')"
> 11 | :max-length="11"
| ^
12 | :icon-type="2"
13 | :icon-left-class="'icon-account orange'"
14 | :error="mobile.length !== 11"
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at src/views/Login/Index.vue:11:1
at Object.<anonymous> (src/views/Login/Index.vue:186:3)
Test Suites: 3 failed, 3 total
Tests: 0 total
Snapshots: 0 total
Time: 2.745s
Ran all test suites.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! newwx.kgjsoft.com@0.1.0 test:unit: jest --clearCache && vue-cli-service test:unit
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the newwx.kgjsoft.com@0.1.0 test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
`
各位路过的大神,求指点迷津~~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看了很多网上的答案,后发现这种比较接近:
由于import xxx from 'xxxx' 是es6语法, jest测试的时候浏览器无法识别es6,必须先将引入的文件转变成es5,而配置中没有安装babel/core 和 babel/preset-env 所以报错