@@ -17,16 +17,42 @@ describe('ssrRenderPortal', () => {
17
17
_push ( `<div>content</div>` )
18
18
} ,
19
19
'#target' ,
20
+ false ,
20
21
_parent
21
22
)
22
23
}
23
24
} ) ,
24
25
ctx
25
26
)
26
- expect ( html ) . toBe ( '<!--portal-->' )
27
+ expect ( html ) . toBe ( '<!--portal start--><!--portal end -->' )
27
28
expect ( ctx . portals ! [ '#target' ] ) . toBe ( `<div>content</div><!---->` )
28
29
} )
29
30
31
+ test ( 'portal rendering (compiled + disabled)' , async ( ) => {
32
+ const ctx : SSRContext = { }
33
+ const html = await renderToString (
34
+ createApp ( {
35
+ data ( ) {
36
+ return { msg : 'hello' }
37
+ } ,
38
+ ssrRender ( _ctx , _push , _parent ) {
39
+ ssrRenderPortal (
40
+ _push ,
41
+ _push => {
42
+ _push ( `<div>content</div>` )
43
+ } ,
44
+ '#target' ,
45
+ true ,
46
+ _parent
47
+ )
48
+ }
49
+ } ) ,
50
+ ctx
51
+ )
52
+ expect ( html ) . toBe ( '<!--portal start--><div>content</div><!--portal end-->' )
53
+ expect ( ctx . portals ! [ '#target' ] ) . toBe ( `<!---->` )
54
+ } )
55
+
30
56
test ( 'portal rendering (vnode)' , async ( ) => {
31
57
const ctx : SSRContext = { }
32
58
const html = await renderToString (
@@ -39,10 +65,27 @@ describe('ssrRenderPortal', () => {
39
65
) ,
40
66
ctx
41
67
)
42
- expect ( html ) . toBe ( '<!--portal-->' )
68
+ expect ( html ) . toBe ( '<!--portal start--><!--portal end -->' )
43
69
expect ( ctx . portals ! [ '#target' ] ) . toBe ( '<span>hello</span><!---->' )
44
70
} )
45
71
72
+ test ( 'portal rendering (vnode + disabled)' , async ( ) => {
73
+ const ctx : SSRContext = { }
74
+ const html = await renderToString (
75
+ h (
76
+ Portal ,
77
+ {
78
+ target : `#target` ,
79
+ disabled : true
80
+ } ,
81
+ h ( 'span' , 'hello' )
82
+ ) ,
83
+ ctx
84
+ )
85
+ expect ( html ) . toBe ( '<!--portal start--><span>hello</span><!--portal end-->' )
86
+ expect ( ctx . portals ! [ '#target' ] ) . toBe ( `<!---->` )
87
+ } )
88
+
46
89
test ( 'multiple portals with same target' , async ( ) => {
47
90
const ctx : SSRContext = { }
48
91
const html = await renderToString (
@@ -58,7 +101,9 @@ describe('ssrRenderPortal', () => {
58
101
] ) ,
59
102
ctx
60
103
)
61
- expect ( html ) . toBe ( '<div><!--portal--><!--portal--></div>' )
104
+ expect ( html ) . toBe (
105
+ '<div><!--portal start--><!--portal end--><!--portal start--><!--portal end--></div>'
106
+ )
62
107
expect ( ctx . portals ! [ '#target' ] ) . toBe (
63
108
'<span>hello</span><!---->world<!---->'
64
109
)
0 commit comments