]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(ssr): test scopeId handling in vdom serialization
authorEvan You <yyx990803@gmail.com>
Thu, 30 Jan 2020 02:13:34 +0000 (21:13 -0500)
committerEvan You <yyx990803@gmail.com>
Thu, 30 Jan 2020 02:13:34 +0000 (21:13 -0500)
packages/server-renderer/__tests__/renderToString.spec.ts
packages/server-renderer/src/renderToString.ts

index a41c4eedc6e9a93ff83e0caf86f2d9c6a70379c7..1736d08f7669b32f1663827e6759e3020f261356 100644 (file)
@@ -1,4 +1,4 @@
-import { createApp, h, createCommentVNode } from 'vue'
+import { createApp, h, createCommentVNode, withScopeId } from 'vue'
 import { renderToString, renderComponent, renderSlot, escapeHtml } from '../src'
 
 describe('ssr: renderToString', () => {
@@ -327,6 +327,41 @@ describe('ssr: renderToString', () => {
   })
 
   describe('scopeId', () => {
-    // TODO
+    // note: here we are only testing scopeId handling for vdom serialization.
+    // compiled srr render functions will include scopeId directly in strings.
+    const withId = withScopeId('data-v-test')
+    const withChildId = withScopeId('data-v-child')
+
+    test('basic', async () => {
+      expect(
+        await renderToString(
+          withId(() => {
+            return h('div')
+          })()
+        )
+      ).toBe(`<div data-v-test></div>`)
+    })
+
+    test('with slots', async () => {
+      const Child = {
+        __scopeId: 'data-v-child',
+        render: withChildId(function(this: any) {
+          return h('div', this.$slots.default())
+        })
+      }
+
+      const Parent = {
+        __scopeId: 'data-v-test',
+        render: withId(() => {
+          return h(Child, null, {
+            default: withId(() => h('span', 'slot'))
+          })
+        })
+      }
+
+      expect(await renderToString(h(Parent))).toBe(
+        `<div data-v-child><span data-v-test data-v-child-s>slot</span></div>`
+      )
+    })
   })
 })
index 7cd7c25ce711d82322f31c76ebba49f887cbee77..ebf96624cfce609f3bfdb22ad16ea93a511dcf4f 100644 (file)
@@ -222,7 +222,7 @@ function renderElement(
     // vnode's own scopeId and the current rendering component's scopeId is
     // different - this is a slot content node.
     if (treeOwnerId != null && treeOwnerId !== scopeId) {
-      openTag += ` ${scopeId}-s`
+      openTag += ` ${treeOwnerId}-s`
     }
   }