]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(runtime-core): add test for `renderSlot` (#1160)
authorunderfin <2218301630@qq.com>
Mon, 18 May 2020 14:14:09 +0000 (22:14 +0800)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 14:14:09 +0000 (10:14 -0400)
packages/runtime-core/__tests__/helpers/renderSlot.spec.ts [new file with mode: 0644]

diff --git a/packages/runtime-core/__tests__/helpers/renderSlot.spec.ts b/packages/runtime-core/__tests__/helpers/renderSlot.spec.ts
new file mode 100644 (file)
index 0000000..3f5e321
--- /dev/null
@@ -0,0 +1,25 @@
+import { renderSlot } from '../../src/helpers/renderSlot'
+import { h } from '../../src/h'
+import { mockWarn } from '@vue/shared'
+
+describe('renderSlot', () => {
+  mockWarn()
+  it('should render slot', () => {
+    let child
+    const vnode = renderSlot(
+      { default: () => [(child = h('child'))] },
+      'default'
+    )
+    expect(vnode.children).toEqual([child])
+  })
+
+  it('should render slot fallback', () => {
+    const vnode = renderSlot({}, 'default', {}, () => ['fallback'])
+    expect(vnode.children).toEqual(['fallback'])
+  })
+
+  it('should warn render ssr slot', () => {
+    renderSlot({ default: (a, b, c) => [h('child')] }, 'default')
+    expect('SSR-optimized slot function detected').toHaveBeenWarned()
+  })
+})