htmldomapi.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { assert } from "chai";
  2. import { init, h, attributesModule } from "../../src/index";
  3. const patch = init([attributesModule]);
  4. describe("svg", function () {
  5. let elm: any, vnode0: any;
  6. beforeEach(function () {
  7. elm = document.createElement("svg");
  8. vnode0 = elm;
  9. });
  10. it("removes child svg elements", function () {
  11. const a = h("svg", {}, [h("g"), h("g")]);
  12. const b = h("svg", {}, [h("g")]);
  13. const result = patch(patch(vnode0, a), b).elm as SVGElement;
  14. assert.strictEqual(result.childNodes.length, 1);
  15. });
  16. it("adds correctly xlink namespaced attribute", function () {
  17. const xlinkNS = "http://www.w3.org/1999/xlink";
  18. const testUrl = "/test";
  19. const a = h("svg", {}, [
  20. h(
  21. "use",
  22. {
  23. attrs: { "xlink:href": testUrl },
  24. },
  25. []
  26. ),
  27. ]);
  28. const result = patch(vnode0, a).elm as SVGElement;
  29. assert.strictEqual(result.childNodes.length, 1);
  30. const child = result.childNodes[0] as SVGUseElement;
  31. assert.strictEqual(child.getAttribute("xlink:href"), testUrl);
  32. assert.strictEqual(child.getAttributeNS(xlinkNS, "href"), testUrl);
  33. });
  34. it("adds correctly xml namespaced attribute", function () {
  35. const xmlNS = "http://www.w3.org/XML/1998/namespace";
  36. const testAttrValue = "und";
  37. const a = h("svg", { attrs: { "xml:lang": testAttrValue } }, []);
  38. const result = patch(vnode0, a).elm as SVGElement;
  39. assert.strictEqual(result.getAttributeNS(xmlNS, "lang"), testAttrValue);
  40. assert.strictEqual(result.getAttribute("xml:lang"), testAttrValue);
  41. });
  42. });