8
8
ref ,
9
9
nextTick
10
10
} from '@vue/runtime-test'
11
- import { createVNode } from '../../src/vnode'
11
+ import { createVNode , Fragment } from '../../src/vnode'
12
12
13
13
describe ( 'renderer: portal' , ( ) => {
14
14
test ( 'should work' , ( ) => {
@@ -24,7 +24,7 @@ describe('renderer: portal', () => {
24
24
)
25
25
26
26
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
27
- `"<!--portal--><div>root</div>"`
27
+ `"<!--portal start--><!--portal end --><div>root</div>"`
28
28
)
29
29
expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
30
30
`"<div>teleported</div>"`
@@ -46,7 +46,7 @@ describe('renderer: portal', () => {
46
46
)
47
47
48
48
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
49
- `"<!--portal--><div>root</div>"`
49
+ `"<!--portal start--><!--portal end --><div>root</div>"`
50
50
)
51
51
expect ( serializeInner ( targetA ) ) . toMatchInlineSnapshot (
52
52
`"<div>teleported</div>"`
@@ -57,7 +57,7 @@ describe('renderer: portal', () => {
57
57
await nextTick ( )
58
58
59
59
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
60
- `"<!--portal--><div>root</div>"`
60
+ `"<!--portal start--><!--portal end --><div>root</div>"`
61
61
)
62
62
expect ( serializeInner ( targetA ) ) . toMatchInlineSnapshot ( `""` )
63
63
expect ( serializeInner ( targetB ) ) . toMatchInlineSnapshot (
@@ -122,7 +122,7 @@ describe('renderer: portal', () => {
122
122
)
123
123
124
124
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
125
- `"<div><!--portal--><!--portal--></div>"`
125
+ `"<div><!--portal start --><!--portal end--><!--portal start--><!--portal end --></div>"`
126
126
)
127
127
expect ( serializeInner ( target ) ) . toMatchInlineSnapshot ( `"<div>one</div>two"` )
128
128
@@ -141,7 +141,7 @@ describe('renderer: portal', () => {
141
141
// toggling
142
142
render ( h ( 'div' , [ null , h ( Portal , { target } , 'three' ) ] ) , root )
143
143
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
144
- `"<div><!----><!--portal--></div>"`
144
+ `"<div><!----><!--portal start--><!--portal end --></div>"`
145
145
)
146
146
expect ( serializeInner ( target ) ) . toMatchInlineSnapshot ( `"three"` )
147
147
@@ -154,7 +154,7 @@ describe('renderer: portal', () => {
154
154
root
155
155
)
156
156
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
157
- `"<div><!--portal--><!--portal--></div>"`
157
+ `"<div><!--portal start --><!--portal end--><!--portal start--><!--portal end --></div>"`
158
158
)
159
159
// should append
160
160
expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
@@ -170,10 +170,133 @@ describe('renderer: portal', () => {
170
170
root
171
171
)
172
172
expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
173
- `"<div><!--portal--><!----></div>"`
173
+ `"<div><!--portal start--><!--portal end --><!----></div>"`
174
174
)
175
175
expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
176
176
`"<div>one</div><div>two</div>"`
177
177
)
178
178
} )
179
+
180
+ test ( 'disabled' , ( ) => {
181
+ const target = nodeOps . createElement ( 'div' )
182
+ const root = nodeOps . createElement ( 'div' )
183
+
184
+ const renderWithDisabled = ( disabled : boolean ) => {
185
+ return h ( Fragment , [
186
+ h ( Portal , { target, disabled } , h ( 'div' , 'teleported' ) ) ,
187
+ h ( 'div' , 'root' )
188
+ ] )
189
+ }
190
+
191
+ render ( renderWithDisabled ( false ) , root )
192
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
193
+ `"<!--portal start--><!--portal end--><div>root</div>"`
194
+ )
195
+ expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
196
+ `"<div>teleported</div>"`
197
+ )
198
+
199
+ render ( renderWithDisabled ( true ) , root )
200
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
201
+ `"<!--portal start--><div>teleported</div><!--portal end--><div>root</div>"`
202
+ )
203
+ expect ( serializeInner ( target ) ) . toBe ( `` )
204
+
205
+ // toggle back
206
+ render ( renderWithDisabled ( false ) , root )
207
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
208
+ `"<!--portal start--><!--portal end--><div>root</div>"`
209
+ )
210
+ expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
211
+ `"<div>teleported</div>"`
212
+ )
213
+ } )
214
+
215
+ test ( 'moving portal while enabled' , ( ) => {
216
+ const target = nodeOps . createElement ( 'div' )
217
+ const root = nodeOps . createElement ( 'div' )
218
+
219
+ render (
220
+ h ( Fragment , [
221
+ h ( Portal , { target } , h ( 'div' , 'teleported' ) ) ,
222
+ h ( 'div' , 'root' )
223
+ ] ) ,
224
+ root
225
+ )
226
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
227
+ `"<!--portal start--><!--portal end--><div>root</div>"`
228
+ )
229
+ expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
230
+ `"<div>teleported</div>"`
231
+ )
232
+
233
+ render (
234
+ h ( Fragment , [
235
+ h ( 'div' , 'root' ) ,
236
+ h ( Portal , { target } , h ( 'div' , 'teleported' ) )
237
+ ] ) ,
238
+ root
239
+ )
240
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
241
+ `"<div>root</div><!--portal start--><!--portal end-->"`
242
+ )
243
+ expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
244
+ `"<div>teleported</div>"`
245
+ )
246
+
247
+ render (
248
+ h ( Fragment , [
249
+ h ( Portal , { target } , h ( 'div' , 'teleported' ) ) ,
250
+ h ( 'div' , 'root' )
251
+ ] ) ,
252
+ root
253
+ )
254
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
255
+ `"<!--portal start--><!--portal end--><div>root</div>"`
256
+ )
257
+ expect ( serializeInner ( target ) ) . toMatchInlineSnapshot (
258
+ `"<div>teleported</div>"`
259
+ )
260
+ } )
261
+
262
+ test ( 'moving portal while disabled' , ( ) => {
263
+ const target = nodeOps . createElement ( 'div' )
264
+ const root = nodeOps . createElement ( 'div' )
265
+
266
+ render (
267
+ h ( Fragment , [
268
+ h ( Portal , { target, disabled : true } , h ( 'div' , 'teleported' ) ) ,
269
+ h ( 'div' , 'root' )
270
+ ] ) ,
271
+ root
272
+ )
273
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
274
+ `"<!--portal start--><div>teleported</div><!--portal end--><div>root</div>"`
275
+ )
276
+ expect ( serializeInner ( target ) ) . toBe ( '' )
277
+
278
+ render (
279
+ h ( Fragment , [
280
+ h ( 'div' , 'root' ) ,
281
+ h ( Portal , { target, disabled : true } , h ( 'div' , 'teleported' ) )
282
+ ] ) ,
283
+ root
284
+ )
285
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
286
+ `"<div>root</div><!--portal start--><div>teleported</div><!--portal end-->"`
287
+ )
288
+ expect ( serializeInner ( target ) ) . toBe ( '' )
289
+
290
+ render (
291
+ h ( Fragment , [
292
+ h ( Portal , { target, disabled : true } , h ( 'div' , 'teleported' ) ) ,
293
+ h ( 'div' , 'root' )
294
+ ] ) ,
295
+ root
296
+ )
297
+ expect ( serializeInner ( root ) ) . toMatchInlineSnapshot (
298
+ `"<!--portal start--><div>teleported</div><!--portal end--><div>root</div>"`
299
+ )
300
+ expect ( serializeInner ( target ) ) . toBe ( '' )
301
+ } )
179
302
} )
0 commit comments