import { createStaticVNode, h, render } from '../src'
describe('static vnode handling', () => {
const content = `
hello
world
`
const content2 = `foo
bar
baz`
const s = createStaticVNode(content, 2)
const s2 = createStaticVNode(content2, 3)
test('should mount from string', () => {
const root = document.createElement('div')
render(h('div', [s]), root)
expect(root.innerHTML).toBe(`${content}
`)
})
test('should support reusing the same hoisted node', () => {
const root = document.createElement('div')
render(h('div', [s, s]), root)
expect(root.innerHTML).toBe(`${content}${content}
`)
})
// the rest only happens during HMR but needs to be correctly supported
test('should update', () => {
const root = document.createElement('div')
render(h('div', [s]), root)
expect(root.innerHTML).toBe(`${content}
`)
render(h('div', [s2]), root)
expect(root.innerHTML).toBe(`${content2}
`)
})
test('should move', () => {
const root = document.createElement('div')
render(h('div', [h('b'), s, h('b')]), root)
expect(root.innerHTML).toBe(`${content}
`)
render(h('div', [s, h('b'), h('b')]), root)
expect(root.innerHTML).toBe(`${content}
`)
render(h('div', [h('b'), h('b'), s]), root)
expect(root.innerHTML).toBe(`${content}
`)
})
test('should remove', () => {
const root = document.createElement('div')
render(h('div', [h('b'), s, h('b')]), root)
expect(root.innerHTML).toBe(`${content}
`)
render(h('div', [h('b'), h('b')]), root)
expect(root.innerHTML).toBe(`
`)
render(h('div', [h('b'), h('b'), s]), root)
expect(root.innerHTML).toBe(`${content}
`)
})
})