fix(test): 🔨修复 vitest 单元测试运行报错等问题

- 在 tests/setup.ts 中添加 __APP_INFO__ 全局 mock
- 在 vitest.config.ts 中配置 AutoImport 插件以支持 Vue API 自动导入
This commit is contained in:
XFeng
2026-01-13 19:45:34 +08:00
parent cc8560a048
commit f41df4a811
2 changed files with 25 additions and 1 deletions

View File

@@ -41,6 +41,14 @@ global.ResizeObserver = class ResizeObserver {
// Mock Element.scrollIntoView
Element.prototype.scrollIntoView = vi.fn();
// Mock __APP_INFO__
(globalThis as any).__APP_INFO__ = {
pkg: {
name: "vue3-element-admin",
version: "4.0.0",
},
};
// Mock console methods to reduce noise in tests
global.console = {
...console,

View File

@@ -1,9 +1,25 @@
import { defineConfig } from "vitest/config";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
export default defineConfig({
plugins: [vue()],
plugins: [
vue(),
// API 自动导入
AutoImport({
imports: ["vue", "@vueuse/core", "pinia", "vue-router", "vue-i18n"],
resolvers: [ElementPlusResolver()],
dts: false,
}),
// 组件自动导入
Components({
resolvers: [ElementPlusResolver()],
dts: false,
}),
],
test: {
// 使用 happy-dom 作为测试环境(比 jsdom 快)
environment: "happy-dom",