fix(test): 🔨修复 vitest 单元测试运行报错等问题
- 在 tests/setup.ts 中添加 __APP_INFO__ 全局 mock - 在 vitest.config.ts 中配置 AutoImport 插件以支持 Vue API 自动导入
This commit is contained in:
@@ -41,6 +41,14 @@ global.ResizeObserver = class ResizeObserver {
|
|||||||
// Mock Element.scrollIntoView
|
// Mock Element.scrollIntoView
|
||||||
Element.prototype.scrollIntoView = vi.fn();
|
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
|
// Mock console methods to reduce noise in tests
|
||||||
global.console = {
|
global.console = {
|
||||||
...console,
|
...console,
|
||||||
|
|||||||
@@ -1,9 +1,25 @@
|
|||||||
import { defineConfig } from "vitest/config";
|
import { defineConfig } from "vitest/config";
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
import { resolve } from "path";
|
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({
|
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: {
|
test: {
|
||||||
// 使用 happy-dom 作为测试环境(比 jsdom 快)
|
// 使用 happy-dom 作为测试环境(比 jsdom 快)
|
||||||
environment: "happy-dom",
|
environment: "happy-dom",
|
||||||
|
|||||||
Reference in New Issue
Block a user