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