如何将getBBox方法添加到SVGElement的原型中?

如何将getBBox方法添加到SVGElement的原型中?,svg,jestjs,window,prototype,Svg,Jestjs,Window,Prototype,jsDom不支持SVG。因此,我试图通过引用链接-,来模拟SVG方法。在将getBBox方法添加到window.SVGElement.prototype时,它抛出错误,指出类型“SVGElement.ts(2339)上不存在属性“getBBox”。编辑器的quick fix将在文件lib.dom.d.ts中的SVGElement接口中添加getBBox方法,该方法仅可读 interface SVGElement extends Element, DocumentAndElementEventHa

jsDom
不支持SVG。因此,我试图通过引用链接-,来模拟SVG方法。在将
getBBox
方法添加到
window.SVGElement.prototype
时,它抛出错误,指出类型“SVGElement.ts(2339)上不存在
属性“getBBox”。编辑器的
quick fix
将在文件
lib.dom.d.ts
中的SVGElement接口中添加getBBox方法,该方法仅可读

interface SVGElement extends Element, DocumentAndElementEventHandlers, ElementCSSInlineStyle, GlobalEventHandlers, HTMLOrSVGElement, SVGElementInstance {
  getBBox: () => { x: number; y: number; height: number; width: number; bottom: number; left: number; right: number; top: number; toJSON: () => void; };
}
以下是实施方案-

  beforeEach(async function () {
     window.SVGElement.prototype.getBBox = () => ({
          x: 0,
          y: 0,
          height: 100,
          width: 100,
          bottom: 100,
          left: 100,
          right: 100,
          top: 100,
          toJSON: () => { }
        });
   });

我如何将
getBBox
方法添加到
SVGElement
接口?参考链接-。

这是否回答了您的问题?这回答了你的问题吗?