@@ -313,6 +313,7 @@ describe('Component slot', () => {
313
313
expect ( 'Render function should return a single root node' ) . toHaveBeenWarned ( )
314
314
} )
315
315
316
+ // #3254
316
317
it ( 'should not keep slot name when passed further down' , ( ) => {
317
318
const vm = new Vue ( {
318
319
template : '<test><span slot="foo">foo<span></test>' ,
@@ -321,7 +322,12 @@ describe('Component slot', () => {
321
322
template : '<child><slot name="foo"></slot></child>' ,
322
323
components : {
323
324
child : {
324
- template : '<div><div class="default"><slot></slot></div><div class="named"><slot name="foo"></slot></div></div>'
325
+ template : `
326
+ <div>
327
+ <div class="default"><slot></slot></div>
328
+ <div class="named"><slot name="foo"></slot></div>
329
+ </div>
330
+ `
325
331
}
326
332
}
327
333
}
@@ -330,4 +336,80 @@ describe('Component slot', () => {
330
336
expect ( vm . $el . querySelector ( '.default' ) . textContent ) . toBe ( 'foo' )
331
337
expect ( vm . $el . querySelector ( '.named' ) . textContent ) . toBe ( '' )
332
338
} )
339
+
340
+ it ( 'should not keep slot name when passed further down (nested)' , ( ) => {
341
+ const vm = new Vue ( {
342
+ template : '<wrap><test><span slot="foo">foo<span></test></wrap>' ,
343
+ components : {
344
+ wrap : {
345
+ template : '<div><slot></slot></div>'
346
+ } ,
347
+ test : {
348
+ template : '<child><slot name="foo"></slot></child>' ,
349
+ components : {
350
+ child : {
351
+ template : `
352
+ <div>
353
+ <div class="default"><slot></slot></div>
354
+ <div class="named"><slot name="foo"></slot></div>
355
+ </div>
356
+ `
357
+ }
358
+ }
359
+ }
360
+ }
361
+ } ) . $mount ( )
362
+ expect ( vm . $el . querySelector ( '.default' ) . textContent ) . toBe ( 'foo' )
363
+ expect ( vm . $el . querySelector ( '.named' ) . textContent ) . toBe ( '' )
364
+ } )
365
+
366
+ it ( 'should not keep slot name when passed further down (functional)' , ( ) => {
367
+ const child = {
368
+ template : `
369
+ <div>
370
+ <div class="default"><slot></slot></div>
371
+ <div class="named"><slot name="foo"></slot></div>
372
+ </div>
373
+ `
374
+ }
375
+ const vm = new Vue ( {
376
+ template : '<test><span slot="foo">foo<span></test>' ,
377
+ components : {
378
+ test : {
379
+ functional : true ,
380
+ render ( h , ctx ) {
381
+ const slots = ctx . slots ( )
382
+ return h ( child , slots . foo )
383
+ }
384
+ }
385
+ }
386
+ } ) . $mount ( )
387
+ console . log ( vm . $el . innerHTML )
388
+ expect ( vm . $el . querySelector ( '.default' ) . textContent ) . toBe ( 'foo' )
389
+ expect ( vm . $el . querySelector ( '.named' ) . textContent ) . toBe ( '' )
390
+ } )
391
+
392
+ // #3400
393
+ it ( 'named slots should be consistent across re-renders' , done => {
394
+ const vm = new Vue ( {
395
+ template : `
396
+ <comp>
397
+ <div slot="foo">foo</div>
398
+ </comp>
399
+ ` ,
400
+ components : {
401
+ comp : {
402
+ data ( ) {
403
+ return { a : 1 }
404
+ } ,
405
+ template : `<div><slot name="foo"></slot>{{ a }}</div>`
406
+ }
407
+ }
408
+ } ) . $mount ( )
409
+ expect ( vm . $el . textContent ) . toBe ( 'foo1' )
410
+ vm . $children [ 0 ] . a = 2
411
+ waitForUpdate ( ( ) => {
412
+ expect ( vm . $el . textContent ) . toBe ( 'foo2' )
413
+ } ) . then ( done )
414
+ } )
333
415
} )
0 commit comments