|
1 | | -import {Element, RawElement} from "."; |
| 1 | +import {Xml} from "."; |
2 | 2 |
|
3 | 3 | describe("internal/xml/xml", () => { |
4 | 4 | describe("render", () => { |
5 | | - it("should render raw elements", () => { |
6 | | - const elem = new RawElement("test"); |
7 | | - expect(elem.render()).toBe("test"); |
8 | | - }); |
9 | | - |
10 | 5 | it("should render element tags", () => { |
11 | | - const elem = new Element("test"); |
12 | | - expect(elem.render()).toBe("<test></test>"); |
| 6 | + const elem = new Xml("test"); |
| 7 | + expect(elem.render()).toBe("<test/>"); |
13 | 8 | }); |
14 | 9 |
|
15 | 10 | it("should render element attributes", () => { |
16 | | - const elem = new Element("test", {a: 1, "b-c": "d"}); |
17 | | - expect(elem.render()).toBe('<test a="1" b-c="d"></test>'); |
| 11 | + const elem = new Xml("test", {a: 1, "b-c": "d"}); |
| 12 | + expect(elem.render()).toBe('<test a="1" b-c="d"/>'); |
18 | 13 | }); |
19 | 14 |
|
20 | | - it("should render element children", () => { |
21 | | - const a = new Element("a"); |
22 | | - const aa = new Element("aa"); |
23 | | - const ab = new Element("ab"); |
24 | | - const aba = new RawElement("aba"); |
25 | | - a.add(aa).add(ab); |
26 | | - ab.add(aba); |
27 | | - expect(a.render()).toBe('<a><aa></aa><ab>aba</ab></a>'); |
| 15 | + it("should render nested elements", () => { |
| 16 | + const a = new Xml("a"); |
| 17 | + const aa = new Xml("aa"); |
| 18 | + const ab = new Xml("ab"); |
| 19 | + const aba = {render: () => "aba"}; |
| 20 | + a.children.push(aa); |
| 21 | + a.children.push(ab); |
| 22 | + ab.children.push(aba); |
| 23 | + expect(a.render()).toBe("<a><aa/><ab>aba</ab></a>"); |
28 | 24 | }); |
29 | 25 | }); |
30 | 26 | }); |
0 commit comments