- 在 tests/setup.ts 中添加 __APP_INFO__ 全局 mock - 在 vitest.config.ts 中配置 AutoImport 插件以支持 Vue API 自动导入
61 lines
1.1 KiB
TypeScript
61 lines
1.1 KiB
TypeScript
/**
|
|
* 测试环境全局配置
|
|
*/
|
|
|
|
import { vi } from "vitest";
|
|
|
|
// Mock window.matchMedia
|
|
Object.defineProperty(window, "matchMedia", {
|
|
writable: true,
|
|
value: vi.fn().mockImplementation((query) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: vi.fn(),
|
|
removeListener: vi.fn(),
|
|
addEventListener: vi.fn(),
|
|
removeEventListener: vi.fn(),
|
|
dispatchEvent: vi.fn(),
|
|
})),
|
|
});
|
|
|
|
// Mock IntersectionObserver
|
|
global.IntersectionObserver = class IntersectionObserver {
|
|
constructor() {}
|
|
disconnect() {}
|
|
observe() {}
|
|
takeRecords() {
|
|
return [];
|
|
}
|
|
unobserve() {}
|
|
} as any;
|
|
|
|
// Mock ResizeObserver
|
|
global.ResizeObserver = class ResizeObserver {
|
|
constructor() {}
|
|
disconnect() {}
|
|
observe() {}
|
|
unobserve() {}
|
|
} as any;
|
|
|
|
// 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,
|
|
log: vi.fn(),
|
|
debug: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
};
|