u
This commit is contained in:
1 parent
f572dce2f6
commit
e99a9fb274
356 files changed
+28877
-1055
No files matched your search
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 单测环境补丁 —— happy-dom 缺少组件依赖的若干浏览器 API。
|
||||
*
|
||||
* happy-dom 没有真实布局引擎,所以:
|
||||
* - 依赖实测尺寸的逻辑(浮层定位、Splitter 拖拽)拿不到有效值,那类行为放到 E2E(Playwright)里验;
|
||||
* - 这里只补「不补就会抛错」的 API,让组件能正常挂载与交互。
|
||||
*/
|
||||
|
||||
class ResizeObserverStub {
|
||||
observe(): void {}
|
||||
unobserve(): void {}
|
||||
disconnect(): void {}
|
||||
}
|
||||
|
||||
if (!('ResizeObserver' in globalThis)) {
|
||||
;(globalThis as unknown as Record<string, unknown>).ResizeObserver = ResizeObserverStub
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
if (!window.matchMedia) {
|
||||
window.matchMedia = ((query: string) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: () => {},
|
||||
removeListener: () => {},
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
dispatchEvent: () => false,
|
||||
})) as unknown as typeof window.matchMedia
|
||||
}
|
||||
|
||||
if (!Element.prototype.scrollIntoView) {
|
||||
Element.prototype.scrollIntoView = () => {}
|
||||
}
|
||||
|
||||
// happy-dom 未实现 PointerEvent 时用 MouseEvent 兜底,保证指针交互的监听能注册
|
||||
if (!('PointerEvent' in window)) {
|
||||
;(window as unknown as Record<string, unknown>).PointerEvent = MouseEvent
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user