File tree 2 files changed +34
-20
lines changed
test/specs/mounting-options
2 files changed +34
-20
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import { throwError } from 'shared/util'
4
4
import { compileToFunctions } from 'vue-template-compiler'
5
+ import { isVueComponent } from '../shared/validators'
5
6
6
7
function isValidSlot ( slot : any ) : boolean {
7
8
return (
8
- Array . isArray ( slot ) ||
9
- ( slot !== null && typeof slot === 'object' ) ||
9
+ isVueComponent ( slot ) ||
10
10
typeof slot === 'string'
11
11
)
12
12
}
@@ -23,24 +23,16 @@ function requiresTemplateCompiler (slot: any): void {
23
23
24
24
export function validateSlots ( slots : SlotsObject ) : void {
25
25
Object . keys ( slots ) . forEach ( key => {
26
- if ( ! isValidSlot ( slots [ key ] ) ) {
27
- throwError (
28
- `slots[key] must be a Component, string or an array ` + `of Components`
29
- )
30
- }
26
+ const slot = Array . isArray ( slots [ key ] ) ? slots [ key ] : [ slots [ key ] ]
31
27
32
- requiresTemplateCompiler ( slots [ key ] )
33
-
34
- if ( Array . isArray ( slots [ key ] ) ) {
35
- slots [ key ] . forEach ( slotValue => {
36
- if ( ! isValidSlot ( slotValue ) ) {
37
- throwError (
38
- `slots[key] must be a Component, string or an array ` +
39
- `of Components`
40
- )
41
- }
42
- requiresTemplateCompiler ( slotValue )
43
- } )
44
- }
28
+ slot . forEach ( slotValue => {
29
+ if ( ! isValidSlot ( slotValue ) ) {
30
+ throwError (
31
+ `slots[key] must be a Component, string or an array ` +
32
+ `of Components`
33
+ )
34
+ }
35
+ requiresTemplateCompiler ( slotValue )
36
+ } )
45
37
} )
46
38
}
Original file line number Diff line number Diff line change @@ -546,4 +546,26 @@ describeWithMountingMethods('options.slots', mountingMethod => {
546
546
wrapper . find ( 'div' ) . trigger ( 'click' )
547
547
}
548
548
)
549
+
550
+ it ( 'mounts component with default slot if passed class component in slot object' , ( ) => {
551
+ const wrapper = mountingMethod ( ComponentWithSlots , {
552
+ slots : { default : ComponentAsAClass }
553
+ } )
554
+ if ( mountingMethod . name === 'renderToString' ) {
555
+ expect ( wrapper ) . contains ( '<div></div>' )
556
+ } else {
557
+ expect ( wrapper . contains ( ComponentAsAClass ) ) . to . equal ( true )
558
+ }
559
+ } )
560
+
561
+ it ( 'mounts component with default slot if passed class component in array in slot object' , ( ) => {
562
+ const wrapper = mountingMethod ( ComponentWithSlots , {
563
+ slots : { default : [ ComponentAsAClass ] }
564
+ } )
565
+ if ( mountingMethod . name === 'renderToString' ) {
566
+ expect ( wrapper ) . contains ( '<div></div>' )
567
+ } else {
568
+ expect ( wrapper . contains ( ComponentAsAClass ) ) . to . equal ( true )
569
+ }
570
+ } )
549
571
} )
You can’t perform that action at this time.
0 commit comments