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