mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
90 lines
3.1 KiB
Plaintext
90 lines
3.1 KiB
Plaintext
<sky>
|
|
<import src="../resources/chai.sky" />
|
|
<import src="../resources/mocha.sky" />
|
|
<import src="../resources/dom-utils.sky" as="DomUtils" />
|
|
<script>
|
|
describe("replaceChild", function() {
|
|
var childElementCount = DomUtils.childElementCount;
|
|
var childNodeCount = DomUtils.childNodeCount;
|
|
|
|
it("should throw with invalid arguments", function() {
|
|
var parent = document.createElement("div");
|
|
assert.throws(function() {
|
|
parent.replaceChild();
|
|
});
|
|
assert.throws(function() {
|
|
parent.replaceChild(null, null);
|
|
});
|
|
assert.throws(function() {
|
|
parent.replaceChild({tagName: "div"});
|
|
});
|
|
assert.throws(function() {
|
|
parent.replaceChild(null, document.createElement("div"));
|
|
});
|
|
assert.throws(function() {
|
|
parent.replaceChild(document.createElement("div"), {tagName: "div"});
|
|
});
|
|
});
|
|
|
|
it("should replace elements", function() {
|
|
var parent = document.createElement("div");
|
|
var oldChild = parent.appendChild(document.createElement("div"));
|
|
var newChild = document.createElement("div");
|
|
parent.replaceChild(newChild, oldChild);
|
|
assert.isNull(oldChild.parentNode);
|
|
assert.equal(newChild.parentNode, parent);
|
|
});
|
|
|
|
it("should replace text", function() {
|
|
var parent = document.createElement("div");
|
|
var oldChild = parent.appendChild(new Text(" it's a text "));
|
|
var newChild = document.createElement("div");
|
|
parent.replaceChild(newChild, oldChild);
|
|
assert.isNull(oldChild.parentNode);
|
|
assert.equal(newChild.parentNode, parent);
|
|
});
|
|
|
|
it("should replace children with a fragment", function() {
|
|
var fragment = document.createDocumentFragment();
|
|
var child1 = fragment.appendChild(document.createElement("div"));
|
|
var child2 = fragment.appendChild(new Text(" text "));
|
|
var child3 = fragment.appendChild(new Text(" "));
|
|
var child4 = fragment.appendChild(document.createElement("div"));
|
|
var parent = document.createElement("div");
|
|
var oldChild = parent.appendChild(document.createElement("div"));
|
|
var lastChild = parent.appendChild(document.createElement("div"));
|
|
parent.replaceChild(fragment, oldChild);
|
|
assert.equal(child1.parentNode, parent);
|
|
assert.equal(child2.parentNode, parent);
|
|
assert.equal(child3.parentNode, parent);
|
|
assert.equal(child4.parentNode, parent);
|
|
assert.isNull(oldChild.parentNode);
|
|
assert.equal(childNodeCount(parent), 5);
|
|
assert.equal(childElementCount(parent), 3);
|
|
assert.equal(parent.lastChild, lastChild);
|
|
});
|
|
|
|
it("should throw when inserting a tree scope", function() {
|
|
var parent = document.createElement("div");
|
|
var doc = new Document();
|
|
var shadowRoot = document.createElement("span").ensureShadowRoot();
|
|
assert.throws(function() {
|
|
parent.replaceChild(doc);
|
|
});
|
|
assert.throws(function() {
|
|
parent.replaceChild(shadowRoot);
|
|
});
|
|
assert.throws(function() {
|
|
doc.replaceChild(fragment);
|
|
});
|
|
});
|
|
|
|
it("should throw when appending to a text", function() {
|
|
var parent = new Text();
|
|
assert.throws(function() {
|
|
parent.replaceChild(document.createElement("div"), null);
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</sky> |