Files
new-markdown/tests/setup.ts

17 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// jsdom 缺失的布局 API 垫片:ProseMirror View 在量测坐标时会调用它们。
// 只补「不抛错」的最小实现,不参与任何断言逻辑。
type RectLike = { x: number; y: number; width: number; height: number; top: number; left: number; right: number; bottom: number; toJSON: () => object }
const emptyRect: RectLike = { x: 0, y: 0, width: 0, height: 0, top: 0, left: 0, right: 0, bottom: 0, toJSON: () => ({}) }
if (typeof Range !== 'undefined') {
Range.prototype.getClientRects = Range.prototype.getClientRects ?? (() => ({ length: 0, item: () => null, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList)
Range.prototype.getBoundingClientRect = Range.prototype.getBoundingClientRect ?? (() => emptyRect as DOMRect)
}
if (typeof Element !== 'undefined') {
Element.prototype.getClientRects = Element.prototype.getClientRects ?? (() => ({ length: 0, item: () => null, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList)
Element.prototype.scrollIntoView = Element.prototype.scrollIntoView ?? (() => undefined)
}
if (typeof document !== 'undefined' && !document.elementFromPoint) {
document.elementFromPoint = () => null
}