我正在使用 Vitest 进行 Vue 单元测试,目前遇到此错误:
FAIL tests/unit/components/MyComponent.spec.js [ tests/unit/components/MyComponent.spec.js ]
SyntaxError: At least one <template> or <script> is required in a single file component.
Run Code Online (Sandbox Code Playgroud)
我的单元测试抱怨没有<template>,<script>但我肯定有这些标签,因为我能够显示网页并且我已经检查了我的组件。问题可能是我的vitest.config.js文件,如下所示:
FAIL tests/unit/components/MyComponent.spec.js [ tests/unit/components/MyComponent.spec.js ]
SyntaxError: At least one <template> or <script> is required in a single file component.
Run Code Online (Sandbox Code Playgroud)
我找到了一个临时修复方法,那就是删除Vue()插件。
export default mergeConfig(
viteConfig,
defineConfig({
plugins: [Vue()],
test: {
globals: true,
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*', 'packages/template/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
transformMode: {
web: [/\.[jt]sx$/]
}
},
root: '.'
})
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
608 次 |
| 最近记录: |