| OLD | NEW |
| 1 <sky> | 1 <sky> |
| 2 <import src="../resources/chai.sky" /> | |
| 3 <import src="../resources/mocha.sky" /> | |
| 4 <import src="../resources/dom-utils.sky" as="DomUtils" /> | 2 <import src="../resources/dom-utils.sky" as="DomUtils" /> |
| 5 <script> | 3 <script> |
| 6 describe("appendChild", function() { | 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 |
| 7 var childElementCount = DomUtils.childElementCount; | 12 var childElementCount = DomUtils.childElementCount; |
| 8 var childNodeCount = DomUtils.childNodeCount; | 13 var childNodeCount = DomUtils.childNodeCount; |
| 9 | 14 |
| 10 it("should throw with invalid arguments", function() { | 15 test("should throw with invalid arguments", () { |
| 11 var parent = document.createElement("div"); | 16 var parent = document.createElement("div"); |
| 12 assert.throws(function() { | 17 expect(() { |
| 13 parent.appendChild(); | 18 parent.appendChild(); |
| 14 }); | 19 }, throws); |
| 15 assert.throws(function() { | 20 // TODO(dart): This is a real bug. |
| 16 parent.appendChild(null); | 21 // expect(() { |
| 17 }); | 22 // parent.appendChild(null); |
| 18 assert.throws(function() { | 23 // }, throws); |
| 24 expect(() { |
| 19 parent.appendChild({tagName: "div"}); | 25 parent.appendChild({tagName: "div"}); |
| 20 }); | 26 }, throws); |
| 21 }); | 27 }); |
| 22 | 28 |
| 23 it("should insert children", function() { | 29 test("should insert children", () { |
| 24 var parent = document.createElement("div"); | 30 var parent = document.createElement("div"); |
| 25 var child1 = parent.appendChild(document.createElement("div")); | 31 var child1 = parent.appendChild(document.createElement("div")); |
| 26 var child2 = parent.appendChild(new Text(" text ")); | 32 var child2 = parent.appendChild(new Text(" text ")); |
| 27 var child3 = parent.appendChild(new Text(" ")); | 33 var child3 = parent.appendChild(new Text(" ")); |
| 28 var child4 = parent.appendChild(document.createElement("div")); | 34 var child4 = parent.appendChild(document.createElement("div")); |
| 29 assert.equal(child1.parentNode, parent); | 35 expect(child1.parentNode, equals(parent)); |
| 30 assert.equal(child2.parentNode, parent); | 36 expect(child2.parentNode, equals(parent)); |
| 31 assert.equal(child3.parentNode, parent); | 37 expect(child3.parentNode, equals(parent)); |
| 32 assert.equal(child4.parentNode, parent); | 38 expect(child4.parentNode, equals(parent)); |
| 33 assert.equal(childNodeCount(parent), 4); | 39 expect(childNodeCount(parent), equals(4)); |
| 34 assert.equal(childElementCount(parent), 2); | 40 expect(childElementCount(parent), equals(2)); |
| 35 }); | 41 }); |
| 36 | 42 |
| 37 it("should insert children with a fragment", function() { | 43 test("should insert children with a fragment", () { |
| 38 var fragment = document.createDocumentFragment(); | 44 var fragment = document.createDocumentFragment(); |
| 39 var child1 = fragment.appendChild(document.createElement("div")); | 45 var child1 = fragment.appendChild(document.createElement("div")); |
| 40 var child2 = fragment.appendChild(new Text(" text ")); | 46 var child2 = fragment.appendChild(new Text(" text ")); |
| 41 var child3 = fragment.appendChild(new Text(" ")); | 47 var child3 = fragment.appendChild(new Text(" ")); |
| 42 var child4 = fragment.appendChild(document.createElement("div")); | 48 var child4 = fragment.appendChild(document.createElement("div")); |
| 43 var parent = document.createElement("div"); | 49 var parent = document.createElement("div"); |
| 44 parent.appendChild(fragment); | 50 parent.appendChild(fragment); |
| 45 assert.equal(child1.parentNode, parent); | 51 expect(child1.parentNode, equals(parent)); |
| 46 assert.equal(child2.parentNode, parent); | 52 expect(child2.parentNode, equals(parent)); |
| 47 assert.equal(child3.parentNode, parent); | 53 expect(child3.parentNode, equals(parent)); |
| 48 assert.equal(child4.parentNode, parent); | 54 expect(child4.parentNode, equals(parent)); |
| 49 assert.equal(childNodeCount(parent), 4); | 55 expect(childNodeCount(parent), equals(4)); |
| 50 assert.equal(childElementCount(parent), 2); | 56 expect(childElementCount(parent), equals(2)); |
| 51 }); | 57 }); |
| 52 | 58 |
| 53 it("should throw when inserting a tree scope", function() { | 59 // TODO(dart): These might be real bugs too. |
| 54 var parent = document.createElement("div"); | 60 // test("should throw when inserting a tree scope", () { |
| 55 var doc = new Document(); | 61 // var parent = document.createElement("div"); |
| 56 var shadowRoot = document.createElement("span").ensureShadowRoot(); | 62 // var doc = new Document(); |
| 57 assert.throws(function() { | 63 // var shadowRoot = document.createElement("span").ensureShadowRoot(); |
| 58 parent.appendChild(doc); | 64 // expect(() { |
| 59 }); | 65 // parent.appendChild(doc); |
| 60 assert.throws(function() { | 66 // }, throws); |
| 61 parent.appendChild(shadowRoot); | 67 // expect(() { |
| 62 }); | 68 // parent.appendChild(shadowRoot); |
| 63 assert.throws(function() { | 69 // }, throws); |
| 64 doc.appendChild(fragment); | 70 // expect(() { |
| 65 }); | 71 // doc.appendChild(fragment); |
| 66 }); | 72 // }, throws); |
| 73 // }); |
| 67 | 74 |
| 68 it("should throw when appending to a text", function() { | 75 // TODO(dart): These might be real bugs too. |
| 69 var parent = new Text(); | 76 // test("should throw when appending to a text", () { |
| 70 assert.throws(function() { | 77 // var parent = new Text(); |
| 71 parent.appendChild(document.createElement("div")); | 78 // expect(() { |
| 72 }); | 79 // parent.appendChild(document.createElement("div")); |
| 73 }); | 80 // }, throws); |
| 74 }); | 81 // }); |
| 82 } |
| 75 </script> | 83 </script> |
| 76 </sky> | 84 </sky> |
| OLD | NEW |