mirror of https://github.com/vuejs/core.git
test(runtime-core): createSlots method (#119)
This commit is contained in:
parent
4605f43b95
commit
fd1d7833e2
|
@ -0,0 +1,56 @@
|
||||||
|
import { Slot } from '../../src/componentSlots'
|
||||||
|
import { createSlots } from '../../src/helpers/createSlots'
|
||||||
|
|
||||||
|
describe('createSlot', () => {
|
||||||
|
const slot = () => []
|
||||||
|
let record: Record<string, Slot>
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
record = {}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should return a slot', () => {
|
||||||
|
const dynamicSlot = [{ name: 'descriptor', fn: slot }]
|
||||||
|
|
||||||
|
const actual = createSlots(record, dynamicSlot)
|
||||||
|
|
||||||
|
expect(actual).toEqual({ descriptor: slot })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should add all slots to the record', () => {
|
||||||
|
const dynamicSlot = [
|
||||||
|
{ name: 'descriptor', fn: slot },
|
||||||
|
{ name: 'descriptor2', fn: slot }
|
||||||
|
]
|
||||||
|
|
||||||
|
const actual = createSlots(record, dynamicSlot)
|
||||||
|
|
||||||
|
expect(actual).toEqual({ descriptor: slot, descriptor2: slot })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should add slot to the record when given slot is an array', () => {
|
||||||
|
const dynamicSlot = [
|
||||||
|
{ name: 'descriptor', fn: slot },
|
||||||
|
[{ name: 'descriptor2', fn: slot }]
|
||||||
|
]
|
||||||
|
|
||||||
|
const actual = createSlots(record, dynamicSlot)
|
||||||
|
|
||||||
|
expect(actual).toEqual({ descriptor: slot, descriptor2: slot })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should add each slot to the record when given slot is an array', () => {
|
||||||
|
const dynamicSlot = [
|
||||||
|
{ name: 'descriptor', fn: slot },
|
||||||
|
[{ name: 'descriptor2', fn: slot }, { name: 'descriptor3', fn: slot }]
|
||||||
|
]
|
||||||
|
|
||||||
|
const actual = createSlots(record, dynamicSlot)
|
||||||
|
|
||||||
|
expect(actual).toEqual({
|
||||||
|
descriptor: slot,
|
||||||
|
descriptor2: slot,
|
||||||
|
descriptor3: slot
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -15,7 +15,7 @@ export function createSlots(
|
||||||
// array of dynamic slot generated by <template v-for="..." #[...]>
|
// array of dynamic slot generated by <template v-for="..." #[...]>
|
||||||
if (isArray(slot)) {
|
if (isArray(slot)) {
|
||||||
for (let j = 0; j < slot.length; j++) {
|
for (let j = 0; j < slot.length; j++) {
|
||||||
slots[slot[i].name] = slot[i].fn
|
slots[slot[j].name] = slot[j].fn
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// conditional single slot generated by <template v-if="..." #foo>
|
// conditional single slot generated by <template v-if="..." #foo>
|
||||||
|
|
Loading…
Reference in New Issue