test: add tests for rendererChildren (#52)
* test: [wip] add tests for rendererChildren * chore: use serializeInner for clearer output * fix: should remove the text node if content is empty * test: also test for appended content * test: inserting & removing * test: moving children * refactor: use a helper function * test: finish tests * test: duplicate keys tests belong to keyed children block * fix(runtime-test): fix insert when moving node in the same parent * fix: fix failing test cases for rendererChildren * test: handle rendererChildren edge case
This commit is contained in:
@@ -155,7 +155,9 @@ function insert(child: TestNode, parent: TestElement, ref?: TestNode | null) {
|
||||
})
|
||||
// remove the node first, but don't log it as a REMOVE op
|
||||
remove(child, false)
|
||||
if (refIndex === undefined) {
|
||||
// re-calculate the ref index because the child's removal may have affected it
|
||||
refIndex = ref ? parent.children.indexOf(ref) : -1
|
||||
if (refIndex === -1) {
|
||||
parent.children.push(child)
|
||||
child.parentNode = parent
|
||||
} else {
|
||||
@@ -195,14 +197,18 @@ function setElementText(el: TestElement, text: string) {
|
||||
el.children.forEach(c => {
|
||||
c.parentNode = null
|
||||
})
|
||||
el.children = [
|
||||
{
|
||||
id: nodeId++,
|
||||
type: NodeTypes.TEXT,
|
||||
text,
|
||||
parentNode: el
|
||||
}
|
||||
]
|
||||
if (!text) {
|
||||
el.children = []
|
||||
} else {
|
||||
el.children = [
|
||||
{
|
||||
id: nodeId++,
|
||||
type: NodeTypes.TEXT,
|
||||
text,
|
||||
parentNode: el
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
function parentNode(node: TestNode): TestElement | null {
|
||||
|
||||
Reference in New Issue
Block a user