如何解决@ quasar / extras / mdi-v4开玩笑的单元测试在意外的令牌“导出”上失败
我正在使用新的SVG图像。我已经为包含徽标的标题mdiMenu创建了一个测试。
从'@ quasar / extras / mdi-v4'导入{mdiMenu} 但是我进行的所有测试:我总是会收到此错误:
paint()
问题来自:
https://forum.quasar-framework.org/topic/5459/quasar-extras-mdi-v4-jest-unit-testing-failing https://forum.vuejs.org/t/quasar-extras-mdi-v4-jest-unit-testing-failing/89973
解决方法
需要设置正确的转换。 因此,您需要正确配置jest.config.js
SyntaxError: Unexpected token 'export'
29 |
30 | <script>
> 31 | import { mdiMenu } from '@quasar/extras/mdi-v4'
Do somebody else have encounter this problem and how can I solve this?
This is the rest of the error message:
This usually means that you are trying to import a file which Jest cannot parse,e.g. it's not plain JavaScript.
By default,if Jest sees a Babel config,it will use that to transform your files,ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed,you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
C:\Users\YohnCheung\work\bitBucket\central-station\node_modules\@quasar\extras\mdi-v4\index.js:3
export const mdiAbTesting = 'M4 2A2 2 0 0 0 2 4V12H4V8H6V12H8V4A2 2 0 0 0 6 2H4M4 4H6V6H4M22 15.5V14A2 2 0 0 0 20 12H16V22H20A2 2 0 0 0 22 20V18.5A1.54 1.54 0 0 0 20.5 17A1.54 1.54 0 0 0 22 15.5M20 20H18V18H20V20M20 16H18V14H20M5.79 21.61L4.21 20.39L18.21 2.39L19.79 3.61Z'
^^^^^^
我的笑话配置正在扩展预设
...
transform: {
'^.+\\.jsx?$': require.resolve('babel-jest'),},...
已包含此转换,但还设置为不转换来自node_modules的步幅
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
因此,在我的配置中,我将模式更改为
transformIgnorePatterns: ['/node_modules/'],
因此它将忽略除类星体之外的所有软件包
希望这个答案对某人有帮助:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。