Skip to content

Commit 21fe83d

Browse files
authored
test: unskip slots tests (#508)
1 parent d588f3e commit 21fe83d

File tree

5 files changed

+421
-385
lines changed

5 files changed

+421
-385
lines changed

packages/create-instance/add-slots.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import { compileToFunctions } from 'vue-template-compiler'
44
import { throwError } from 'shared/util'
5-
6-
function isValidSlot (slot: any): boolean {
7-
return true
8-
}
5+
import { validateSlots } from './validate-slots'
96

107
function addSlotToVm (vm: Component, slotName: string, slotValue: Component | string | Array<Component> | Array<string>): void {
118
let elem
@@ -47,16 +44,10 @@ function addSlotToVm (vm: Component, slotName: string, slotValue: Component | st
4744
}
4845

4946
export function addSlots (vm: Component, slots: Object): void {
47+
validateSlots(slots)
5048
Object.keys(slots).forEach((key) => {
51-
if (!isValidSlot(slots[key])) {
52-
throwError('slots[key] must be a Component, string or an array of Components')
53-
}
54-
5549
if (Array.isArray(slots[key])) {
5650
slots[key].forEach((slotValue) => {
57-
if (!isValidSlot(slotValue)) {
58-
throwError('slots[key] must be a Component, string or an array of Components')
59-
}
6051
addSlotToVm(vm, key, slotValue)
6152
})
6253
} else {

packages/create-instance/create-functional-component.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import { compileToFunctions } from 'vue-template-compiler'
44
import { throwError } from 'shared/util'
5-
6-
function isValidSlot (slot: any): boolean {
7-
return Array.isArray(slot) || (slot !== null && typeof slot === 'object') || typeof slot === 'string'
8-
}
5+
import { validateSlots } from './validate-slots'
96

107
function createFunctionalSlots (slots = {}, h) {
118
if (Array.isArray(slots.default)) {
@@ -19,18 +16,12 @@ function createFunctionalSlots (slots = {}, h) {
1916
Object.keys(slots).forEach(slotType => {
2017
if (Array.isArray(slots[slotType])) {
2118
slots[slotType].forEach(slot => {
22-
if (!isValidSlot(slot)) {
23-
throwError('slots[key] must be a Component, string or an array of Components')
24-
}
2519
const component = typeof slot === 'string' ? compileToFunctions(slot) : slot
2620
const newSlot = h(component)
2721
newSlot.data.slot = slotType
2822
children.push(newSlot)
2923
})
3024
} else {
31-
if (!isValidSlot(slots[slotType])) {
32-
throwError('slots[key] must be a Component, string or an array of Components')
33-
}
3425
const component = typeof slots[slotType] === 'string' ? compileToFunctions(slots[slotType]) : slots[slotType]
3526
const slot = h(component)
3627
slot.data.slot = slotType
@@ -44,6 +35,9 @@ export default function createFunctionalComponent (component: Component, mountin
4435
if (mountingOptions.context && typeof mountingOptions.context !== 'object') {
4536
throwError('mount.context must be an object')
4637
}
38+
if (mountingOptions.slots) {
39+
validateSlots(mountingOptions.slots)
40+
}
4741

4842
return {
4943
render (h: Function) {
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @flow
2+
3+
import { throwError } from 'shared/util'
4+
5+
function isValidSlot (slot: any): boolean {
6+
return Array.isArray(slot) || (slot !== null && typeof slot === 'object') || typeof slot === 'string'
7+
}
8+
9+
export function validateSlots (slots: Object): void {
10+
slots && Object.keys(slots).forEach((key) => {
11+
if (!isValidSlot(slots[key])) {
12+
throwError('slots[key] must be a Component, string or an array of Components')
13+
}
14+
15+
if (Array.isArray(slots[key])) {
16+
slots[key].forEach((slotValue) => {
17+
if (!isValidSlot(slotValue)) {
18+
throwError('slots[key] must be a Component, string or an array of Components')
19+
}
20+
})
21+
}
22+
})
23+
}

0 commit comments

Comments
 (0)