@@ -17,9 +17,12 @@ import {
17
17
onUnmounted ,
18
18
onErrorCaptured ,
19
19
shallowRef ,
20
+ SuspenseProps ,
21
+ resolveDynamicComponent ,
20
22
Fragment
21
23
} from '@vue/runtime-test'
22
24
import { createApp , defineComponent } from 'vue'
25
+ import { type RawSlots } from 'packages/runtime-core/src/componentSlots'
23
26
24
27
describe ( 'Suspense' , ( ) => {
25
28
const deps : Promise < any > [ ] = [ ]
@@ -1523,4 +1526,75 @@ describe('Suspense', () => {
1523
1526
expected = `<div>outerB</div><div>innerB</div>`
1524
1527
expect ( serializeInner ( root ) ) . toBe ( expected )
1525
1528
} )
1529
+
1530
+ describe ( 'warnings' , ( ) => {
1531
+ // base function to check if a combination of slots warns or not
1532
+ function baseCheckWarn (
1533
+ shouldWarn : boolean ,
1534
+ children : RawSlots ,
1535
+ props : SuspenseProps | null = null
1536
+ ) {
1537
+ const Comp = {
1538
+ setup ( ) {
1539
+ return ( ) => h ( Suspense , props , children )
1540
+ }
1541
+ }
1542
+
1543
+ const root = nodeOps . createElement ( 'div' )
1544
+ render ( h ( Comp ) , root )
1545
+
1546
+ if ( shouldWarn ) {
1547
+ expect ( `<Suspense> slots expect a single root node.` ) . toHaveBeenWarned ( )
1548
+ } else {
1549
+ expect (
1550
+ `<Suspense> slots expect a single root node.`
1551
+ ) . not . toHaveBeenWarned ( )
1552
+ }
1553
+ }
1554
+
1555
+ // actual function that we use in tests
1556
+ const checkWarn = baseCheckWarn . bind ( null , true )
1557
+ const checkNoWarn = baseCheckWarn . bind ( null , false )
1558
+
1559
+ test ( 'does not warn on single child' , async ( ) => {
1560
+ checkNoWarn ( {
1561
+ default : h ( 'div' ) ,
1562
+ fallback : h ( 'div' )
1563
+ } )
1564
+ } )
1565
+
1566
+ test ( 'does not warn on null' , async ( ) => {
1567
+ checkNoWarn ( {
1568
+ default : null ,
1569
+ fallback : null
1570
+ } )
1571
+ } )
1572
+
1573
+ test ( 'does not warn on <component :is="null" />' , async ( ) => {
1574
+ checkNoWarn ( {
1575
+ default : ( ) => [ resolveDynamicComponent ( null ) ] ,
1576
+ fallback : ( ) => null
1577
+ } )
1578
+ } )
1579
+
1580
+ test ( 'does not warn on empty array' , async ( ) => {
1581
+ checkNoWarn ( {
1582
+ default : [ ] ,
1583
+ fallback : ( ) => [ ]
1584
+ } )
1585
+ } )
1586
+
1587
+ test ( 'warns on multiple children in default' , async ( ) => {
1588
+ checkWarn ( {
1589
+ default : [ h ( 'div' ) , h ( 'div' ) ]
1590
+ } )
1591
+ } )
1592
+
1593
+ test ( 'warns on multiple children in fallback' , async ( ) => {
1594
+ checkWarn ( {
1595
+ default : h ( 'div' ) ,
1596
+ fallback : [ h ( 'div' ) , h ( 'div' ) ]
1597
+ } )
1598
+ } )
1599
+ } )
1526
1600
} )
0 commit comments