|
| 1 | +import { createStaticVNode, h, render } from '../src' |
| 2 | + |
| 3 | +describe('static vnode handling', () => { |
| 4 | + const content = `<div>hello</div><p>world</p>` |
| 5 | + const content2 = `<p>foo</p><div>bar</div><span>baz</span>` |
| 6 | + |
| 7 | + const s = createStaticVNode(content, 2) |
| 8 | + const s2 = createStaticVNode(content2, 3) |
| 9 | + |
| 10 | + test('should mount from string', () => { |
| 11 | + const root = document.createElement('div') |
| 12 | + render(h('div', [s]), root) |
| 13 | + expect(root.innerHTML).toBe(`<div>${content}</div>`) |
| 14 | + }) |
| 15 | + |
| 16 | + test('should support reusing the same hoisted node', () => { |
| 17 | + const root = document.createElement('div') |
| 18 | + render(h('div', [s, s]), root) |
| 19 | + expect(root.innerHTML).toBe(`<div>${content}${content}</div>`) |
| 20 | + }) |
| 21 | + |
| 22 | + // the rest only happens during HMR but needs to be correctly supported |
| 23 | + test('should update', () => { |
| 24 | + const root = document.createElement('div') |
| 25 | + render(h('div', [s]), root) |
| 26 | + expect(root.innerHTML).toBe(`<div>${content}</div>`) |
| 27 | + render(h('div', [s2]), root) |
| 28 | + expect(root.innerHTML).toBe(`<div>${content2}</div>`) |
| 29 | + }) |
| 30 | + |
| 31 | + test('should move', () => { |
| 32 | + const root = document.createElement('div') |
| 33 | + render(h('div', [h('b'), s, h('b')]), root) |
| 34 | + expect(root.innerHTML).toBe(`<div><b></b>${content}<b></b></div>`) |
| 35 | + render(h('div', [s, h('b'), h('b')]), root) |
| 36 | + expect(root.innerHTML).toBe(`<div>${content}<b></b><b></b></div>`) |
| 37 | + render(h('div', [h('b'), h('b'), s]), root) |
| 38 | + expect(root.innerHTML).toBe(`<div><b></b><b></b>${content}</div>`) |
| 39 | + }) |
| 40 | + |
| 41 | + test('should remove', () => { |
| 42 | + const root = document.createElement('div') |
| 43 | + render(h('div', [h('b'), s, h('b')]), root) |
| 44 | + expect(root.innerHTML).toBe(`<div><b></b>${content}<b></b></div>`) |
| 45 | + render(h('div', [h('b'), h('b')]), root) |
| 46 | + expect(root.innerHTML).toBe(`<div><b></b><b></b></div>`) |
| 47 | + render(h('div', [h('b'), h('b'), s]), root) |
| 48 | + expect(root.innerHTML).toBe(`<div><b></b><b></b>${content}</div>`) |
| 49 | + }) |
| 50 | +}) |
0 commit comments