]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(vnode): tests for normlaizeVNode
authorEvan You <yyx990803@gmail.com>
Fri, 11 Oct 2019 15:41:28 +0000 (11:41 -0400)
committerEvan You <yyx990803@gmail.com>
Fri, 11 Oct 2019 15:41:28 +0000 (11:41 -0400)
packages/runtime-core/__tests__/vnode.spec.ts

index dbcc1da32818735e77d8d058f78a40cfdb703171..b25494ee7eb56ee8c901811d27dabd80ebbf28cf 100644 (file)
@@ -1,6 +1,6 @@
 import { createVNode } from '@vue/runtime-test'
-import { ShapeFlags } from '@vue/runtime-core'
-import { mergeProps } from '../src/vnode'
+import { ShapeFlags, Comment, Fragment, Text } from '@vue/runtime-core'
+import { mergeProps, normalizeVNode } from '../src/vnode'
 import { Data } from '../src/component'
 
 describe('vnode', () => {
@@ -109,7 +109,30 @@ describe('vnode', () => {
     })
   })
 
-  test.todo('normalizeVNode')
+  test('normalizeVNode', () => {
+    // null / undefined -> Comment
+    expect(normalizeVNode(null)).toMatchObject({ type: Comment })
+    expect(normalizeVNode(undefined)).toMatchObject({ type: Comment })
+
+    // array -> Fragment
+    expect(normalizeVNode(['foo'])).toMatchObject({ type: Fragment })
+
+    // VNode -> VNode
+    const vnode = createVNode('div')
+    expect(normalizeVNode(vnode)).toBe(vnode)
+
+    // mounted VNode -> cloned VNode
+    const mounted = createVNode('div')
+    mounted.el = {}
+    const normlaized = normalizeVNode(mounted)
+    expect(normlaized).not.toBe(mounted)
+    expect(normlaized).toEqual({ ...mounted, el: null })
+
+    // primitive types
+    expect(normalizeVNode('foo')).toMatchObject({ type: Text, children: `foo` })
+    expect(normalizeVNode(1)).toMatchObject({ type: Text, children: `1` })
+    expect(normalizeVNode(true)).toMatchObject({ type: Text, children: `true` })
+  })
 
   test.todo('node type/shapeFlag inference')