Skip to content

Commit fd1d783

Browse files
kyle-hallyyx990803
authored andcommitted
test(runtime-core): createSlots method (vuejs#119)
1 parent 4605f43 commit fd1d783

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Slot } from '../../src/componentSlots'
2+
import { createSlots } from '../../src/helpers/createSlots'
3+
4+
describe('createSlot', () => {
5+
const slot = () => []
6+
let record: Record<string, Slot>
7+
8+
beforeEach(() => {
9+
record = {}
10+
})
11+
12+
it('should return a slot', () => {
13+
const dynamicSlot = [{ name: 'descriptor', fn: slot }]
14+
15+
const actual = createSlots(record, dynamicSlot)
16+
17+
expect(actual).toEqual({ descriptor: slot })
18+
})
19+
20+
it('should add all slots to the record', () => {
21+
const dynamicSlot = [
22+
{ name: 'descriptor', fn: slot },
23+
{ name: 'descriptor2', fn: slot }
24+
]
25+
26+
const actual = createSlots(record, dynamicSlot)
27+
28+
expect(actual).toEqual({ descriptor: slot, descriptor2: slot })
29+
})
30+
31+
it('should add slot to the record when given slot is an array', () => {
32+
const dynamicSlot = [
33+
{ name: 'descriptor', fn: slot },
34+
[{ name: 'descriptor2', fn: slot }]
35+
]
36+
37+
const actual = createSlots(record, dynamicSlot)
38+
39+
expect(actual).toEqual({ descriptor: slot, descriptor2: slot })
40+
})
41+
42+
it('should add each slot to the record when given slot is an array', () => {
43+
const dynamicSlot = [
44+
{ name: 'descriptor', fn: slot },
45+
[{ name: 'descriptor2', fn: slot }, { name: 'descriptor3', fn: slot }]
46+
]
47+
48+
const actual = createSlots(record, dynamicSlot)
49+
50+
expect(actual).toEqual({
51+
descriptor: slot,
52+
descriptor2: slot,
53+
descriptor3: slot
54+
})
55+
})
56+
})

packages/runtime-core/src/helpers/createSlots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createSlots(
1515
// array of dynamic slot generated by <template v-for="..." #[...]>
1616
if (isArray(slot)) {
1717
for (let j = 0; j < slot.length; j++) {
18-
slots[slot[i].name] = slot[i].fn
18+
slots[slot[j].name] = slot[j].fn
1919
}
2020
} else {
2121
// conditional single slot generated by <template v-if="..." #foo>

0 commit comments

Comments
 (0)