[DOM Mock] Fix insertBefore when the reference node follows the moving child in a nodeList
This commit is contained in:
parent
c6693aa361
commit
9136585fe4
2 changed files with 23 additions and 0 deletions
|
|
@ -101,6 +101,7 @@ module.exports = function(options) {
|
||||||
if (index > -1) this.childNodes.splice(index, 1)
|
if (index > -1) this.childNodes.splice(index, 1)
|
||||||
if (reference === null) this.appendChild(child)
|
if (reference === null) this.appendChild(child)
|
||||||
else {
|
else {
|
||||||
|
if (index !== -1 && refIndex > index) refIndex--
|
||||||
if (child.nodeType === 11) {
|
if (child.nodeType === 11) {
|
||||||
this.childNodes.splice.apply(this.childNodes, [refIndex, 0].concat(child.childNodes))
|
this.childNodes.splice.apply(this.childNodes, [refIndex, 0].concat(child.childNodes))
|
||||||
while (child.firstChild) {
|
while (child.firstChild) {
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,28 @@ o.spec("domMock", function() {
|
||||||
o(a.parentNode).equals(parent)
|
o(a.parentNode).equals(parent)
|
||||||
o(b.parentNode).equals(parent)
|
o(b.parentNode).equals(parent)
|
||||||
})
|
})
|
||||||
|
o("moves existing node forward but not at the end", function() {
|
||||||
|
var parent = $document.createElement("div")
|
||||||
|
var a = $document.createElement("a")
|
||||||
|
var b = $document.createElement("b")
|
||||||
|
var c = $document.createElement("c")
|
||||||
|
parent.appendChild(a)
|
||||||
|
parent.appendChild(b)
|
||||||
|
parent.appendChild(c)
|
||||||
|
parent.insertBefore(a, c)
|
||||||
|
|
||||||
|
o(parent.childNodes.length).equals(3)
|
||||||
|
o(parent.childNodes[0]).equals(b)
|
||||||
|
o(parent.childNodes[1]).equals(a)
|
||||||
|
o(parent.childNodes[2]).equals(c)
|
||||||
|
o(parent.firstChild).equals(b)
|
||||||
|
o(parent.firstChild.nextSibling).equals(a)
|
||||||
|
o(parent.firstChild.nextSibling.nextSibling).equals(c)
|
||||||
|
o(a.parentNode).equals(parent)
|
||||||
|
o(b.parentNode).equals(parent)
|
||||||
|
o(c.parentNode).equals(parent)
|
||||||
|
|
||||||
|
})
|
||||||
o("removes from old parent", function() {
|
o("removes from old parent", function() {
|
||||||
var parent = $document.createElement("div")
|
var parent = $document.createElement("div")
|
||||||
var source = $document.createElement("span")
|
var source = $document.createElement("span")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue