OLD | NEW |
| (Empty) |
1 <sky> | |
2 <import src="../resources/dom-utils.sky" as="DomUtils" /> | |
3 <script> | |
4 import "../resources/third_party/unittest/unittest.dart"; | |
5 import "../resources/unit.dart"; | |
6 | |
7 import "dart:sky"; | |
8 | |
9 void main() { | |
10 initUnit(); | |
11 | |
12 var childElementCount = DomUtils.childElementCount; | |
13 var childNodeCount = DomUtils.childNodeCount; | |
14 | |
15 test("should replace elements", () { | |
16 var parent = document.createElement("div"); | |
17 var oldChild = parent.appendChild(document.createElement("div")); | |
18 var newChild = document.createElement("div"); | |
19 oldChild.replaceWith([newChild]); | |
20 expect(oldChild.parentNode, isNull); | |
21 expect(newChild.parentNode, equals(parent)); | |
22 }); | |
23 | |
24 test("should replace text", () { | |
25 var parent = document.createElement("div"); | |
26 var oldChild = parent.appendChild(new Text(" it's a text ")); | |
27 var newChild = document.createElement("div"); | |
28 oldChild.replaceWith([newChild]); | |
29 expect(oldChild.parentNode, isNull); | |
30 expect(newChild.parentNode, equals(parent)); | |
31 }); | |
32 | |
33 test("should replace children with a fragment", () { | |
34 var fragment = document.createDocumentFragment(); | |
35 var child1 = fragment.appendChild(document.createElement("div")); | |
36 var child2 = fragment.appendChild(new Text(" text ")); | |
37 var child3 = fragment.appendChild(new Text(" ")); | |
38 var child4 = fragment.appendChild(document.createElement("div")); | |
39 var parent = document.createElement("div"); | |
40 var oldChild = parent.appendChild(document.createElement("div")); | |
41 var lastChild = parent.appendChild(document.createElement("div")); | |
42 oldChild.replaceWith([fragment]); | |
43 expect(child1.parentNode, equals(parent)); | |
44 expect(child2.parentNode, equals(parent)); | |
45 expect(child3.parentNode, equals(parent)); | |
46 expect(child4.parentNode, equals(parent)); | |
47 expect(oldChild.parentNode, isNull); | |
48 expect(childNodeCount(parent), equals(5)); | |
49 expect(childElementCount(parent), equals(3)); | |
50 expect(parent.lastChild, equals(lastChild)); | |
51 }); | |
52 | |
53 // test("should throw when inserting a tree scope", () { | |
54 // var parent = document.createElement("div"); | |
55 // var doc = new Document(); | |
56 // var shadowRoot = document.createElement("span").ensureShadowRoot(); | |
57 // expect(() { | |
58 // parent.replaceChild(doc); | |
59 // }, throws); | |
60 // expect(() { | |
61 // parent.replaceChild(shadowRoot); | |
62 // }, throws); | |
63 // expect(() { | |
64 // doc.replaceChild(fragment); | |
65 // }, throws); | |
66 // }); | |
67 | |
68 // test("should throw when appending to a text", () { | |
69 // var parent = new Text(); | |
70 // expect(() { | |
71 // parent.replaceChild(document.createElement("div"), null); | |
72 // }, throws); | |
73 // }); | |
74 } | |
75 </script> | |
76 </sky> | |
OLD | NEW |