File tree Expand file tree Collapse file tree 2 files changed +34
-20
lines changed
test/specs/mounting-options Expand file tree Collapse file tree 2 files changed +34
-20
lines changed Original file line number Diff line number Diff line change 22
33import { throwError } from 'shared/util'
44import { compileToFunctions } from 'vue-template-compiler'
5+ import { isVueComponent } from '../shared/validators'
56
67function isValidSlot ( slot : any ) : boolean {
78 return (
8- Array . isArray ( slot ) ||
9- ( slot !== null && typeof slot === 'object' ) ||
9+ isVueComponent ( slot ) ||
1010 typeof slot === 'string'
1111 )
1212}
@@ -23,24 +23,16 @@ function requiresTemplateCompiler (slot: any): void {
2323
2424export function validateSlots ( slots : SlotsObject ) : void {
2525 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 ] ]
3127
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+ } )
4537 } )
4638}
Original file line number Diff line number Diff line change @@ -546,4 +546,26 @@ describeWithMountingMethods('options.slots', mountingMethod => {
546546 wrapper . find ( 'div' ) . trigger ( 'click' )
547547 }
548548 )
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+ } )
549571} )
You can’t perform that action at this time.
0 commit comments