0
我下載[email protected]讓我的反應項目的測試更容易 但我發現了jsdom不能創建SVG元素
代碼如下:。jsdom不支持SVG
const dc = (new JSDOM(`...`)).window.document;
var svg = dc.createElementNS("http://www.w3.org/2000/svg", "svg");
var div = dc.createElement("div");
var svg2 = dc.createElement("svg");
console.log("svg:", svg, svg.createSVGPoint);
console.log("div:", div);
console.log("svg2:", svg2, svg2.createSVGPoint);
,其結果是:
svg: HTMLUnknownElement {} undefined
div: HTMLDivElement {}
svg2: HTMLUnknownElement {} undefined
我想要做一些測試,我的代碼,但SVG是不行的。
我需要幫助。 非常感謝你!
好像它意,即SVG由代表HTMLUnkownElement:https://github.com/tmpvar/jsdom/issues/1371#issuecomment-177606614 – Scarysize
@Scarysize官方使用像這樣:'svg.outerHtml',我知道它的類型是字符串。所以,我使用jQuery將其切換到typeof'Node'並嘗試函數createSVGPoint:'$(svg.outerHtml)[0] .createSVGPoint',結果是:'undefined' ----- :(我讀了相關的問題關於,核心問題也是[email protected]不支持SVG –
outerHTML和innerHTML總是返回字符串 – slebetman