20260819173221

This commit is contained in:
oneao committed 2026-08-19 17:32:25 +08:00
1 parent 1ffc8e1ac9
commit a0a4273f4c
326 files changed
+301646 -2314

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
import { vi } from 'vitest'
// 路由守卫依赖 nprogress,jsdom 下避免其 DOM 副作用
vi.mock('nprogress', () => ({
default: { configure: vi.fn(), start: vi.fn(), done: vi.fn() },
configure: vi.fn(),
start: vi.fn(),
done: vi.fn(),
}))
// ----- jsdom 缺失的浏览器 API polyfill -----
// 自建 UI 组件(modal/select/dropdown/tree 等)常依赖以下全局对象,jsdom 未实现,需补桩。
// ResizeObserver:组件监听元素尺寸时使用
if (!globalThis.ResizeObserver) {
globalThis.ResizeObserver = class {
observe() {}
unobserve() {}
disconnect() {}
}
}
// IntersectionObserver:虚拟列表/懒加载等使用
if (!globalThis.IntersectionObserver) {
globalThis.IntersectionObserver = class {
constructor() {}
observe() {}
unobserve() {}
disconnect() {}
takeRecords() {
return []
}
}
}
// matchMedia:主题/响应式/偏好判断使用
if (!globalThis.matchMedia) {
globalThis.matchMedia = (query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})
}
// 元素滚动方法:jsdom 未实现会抛 "not implemented"
if (!Element.prototype.scrollTo) {
Element.prototype.scrollTo = vi.fn()
}
if (!Element.prototype.scrollIntoView) {
Element.prototype.scrollIntoView = vi.fn()
}