refactor: simplify static content insertion

This commit is contained in:
Evan You
2021-07-09 16:18:36 -04:00
parent 5df7dfcd71
commit c0db807844
4 changed files with 30 additions and 94 deletions

View File

@@ -32,9 +32,8 @@ describe('runtime-dom: node-ops', () => {
const parent = document.createElement('div')
const nodes = nodeOps.insertStaticContent!(content, parent, null, false)
expect(parent.innerHTML).toBe(content)
expect(nodes.length).toBe(3)
expect(nodes[0]).toBe(parent.firstChild)
expect(nodes[nodes.length - 1]).toBe(parent.lastChild)
expect(nodes[1]).toBe(parent.lastChild)
})
test('fresh insertion with anchor', () => {
@@ -45,11 +44,8 @@ describe('runtime-dom: node-ops', () => {
const anchor = parent.firstChild
const nodes = nodeOps.insertStaticContent!(content, parent, anchor, false)
expect(parent.innerHTML).toBe(content + existing)
expect(nodes.length).toBe(3)
expect(nodes[0]).toBe(parent.firstChild)
expect(nodes[nodes.length - 1]).toBe(
parent.childNodes[parent.childNodes.length - 2]
)
expect(nodes[1]).toBe(parent.childNodes[parent.childNodes.length - 2])
})
test('fresh insertion as svg', () => {
@@ -86,32 +82,5 @@ describe('runtime-dom: node-ops', () => {
expect(first.namespaceURI).toMatch('svg')
expect(last.namespaceURI).toMatch('svg')
})
test('cached', () => {
const content = `<div>one</div><div>two</div>three`
const cacheParent = document.createElement('div')
const nodes = nodeOps.insertStaticContent!(
content,
cacheParent,
null,
false
)
const parent = document.createElement('div')
const clonedNodes = nodeOps.insertStaticContent!(
``,
parent,
null,
false,
nodes
)
expect(parent.innerHTML).toBe(content)
expect(clonedNodes[0]).toBe(parent.firstChild)
expect(clonedNodes[clonedNodes.length - 1]).toBe(parent.lastChild)
expect(clonedNodes[0]).not.toBe(nodes[0])
})
})
})