]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(runtime-core): createSlots method (#119)
authorKyle Hall <kyle-hall@users.noreply.github.com>
Mon, 7 Oct 2019 00:19:44 +0000 (19:19 -0500)
committerEvan You <yyx990803@gmail.com>
Mon, 7 Oct 2019 00:19:44 +0000 (20:19 -0400)
packages/runtime-core/__tests__/helpers/createSlots.spec.ts [new file with mode: 0644]
packages/runtime-core/src/helpers/createSlots.ts

diff --git a/packages/runtime-core/__tests__/helpers/createSlots.spec.ts b/packages/runtime-core/__tests__/helpers/createSlots.spec.ts
new file mode 100644 (file)
index 0000000..7f1de63
--- /dev/null
@@ -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
+    })
+  })
+})
index 0113571741eeb563682e790d36177b759491281f..b78b52ae3eec3f2188892e80e7aeb1dc8137e7e6 100644 (file)
@@ -15,7 +15,7 @@ export function createSlots(
     // array of dynamic slot generated by <template v-for="..." #[...]>
     if (isArray(slot)) {
       for (let j = 0; j < slot.length; j++) {
-        slots[slot[i].name] = slot[i].fn
+        slots[slot[j].name] = slot[j].fn
       }
     } else {
       // conditional single slot generated by <template v-if="..." #foo>