-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
rendererPortal.spec.ts
84 lines (69 loc) · 2.07 KB
/
rendererPortal.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
nodeOps,
serializeInner,
render,
h,
createComponent,
Portal,
Text,
Fragment,
ref,
nextTick,
TestElement,
TestNode
} from '@vue/runtime-test'
import { VNodeChildren } from '../src/vnode'
describe('renderer: portal', () => {
test('should work', () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
const Comp = createComponent(() => () =>
h(Fragment, [
h(Portal, { target }, h('div', 'teleported')),
h('div', 'root')
])
)
render(h(Comp), root)
expect(serializeInner(root)).toMatchSnapshot()
expect(serializeInner(target)).toMatchSnapshot()
})
test('should update target', async () => {
const targetA = nodeOps.createElement('div')
const targetB = nodeOps.createElement('div')
const target = ref(targetA)
const root = nodeOps.createElement('div')
const Comp = createComponent(() => () =>
h(Fragment, [
h(Portal, { target: target.value }, h('div', 'teleported')),
h('div', 'root')
])
)
render(h(Comp), root)
expect(serializeInner(root)).toMatchSnapshot()
expect(serializeInner(targetA)).toMatchSnapshot()
expect(serializeInner(targetB)).toMatchSnapshot()
target.value = targetB
await nextTick()
expect(serializeInner(root)).toMatchSnapshot()
expect(serializeInner(targetA)).toMatchSnapshot()
expect(serializeInner(targetB)).toMatchSnapshot()
})
test('should update children', async () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
const children = ref<VNodeChildren<TestNode, TestElement>>([
h('div', 'teleported')
])
const Comp = createComponent(() => () =>
h(Portal, { target }, children.value)
)
render(h(Comp), root)
expect(serializeInner(target)).toMatchSnapshot()
children.value = []
await nextTick()
expect(serializeInner(target)).toMatchSnapshot()
children.value = [h(Text, 'teleported')]
await nextTick()
expect(serializeInner(target)).toMatchSnapshot()
})
})