Как добавить метод getBBox к прототипу SVGElement? - PullRequest
1 голос
/ 08 марта 2020

jsDom не поддерживает SVG. Поэтому я пытаюсь смоделировать методы SVG, ссылаясь на ссылку - https://github.com/jsdom/jsdom/issues/1664. При добавлении метода getBBox к window.SVGElement.prototype выдается сообщение об ошибке Property 'getBBox' does not exist on type 'SVGElement'.ts(2339). quick fix редактора добавит метод getBBox в интерфейс SVGElement в файл lib.dom.d.ts, который доступен только для чтения.

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 интерфейс? Ссылка - https://github.com/jsdom/jsdom/issues/1664.

...