From: Evan You Date: Fri, 11 Oct 2019 15:41:28 +0000 (-0400) Subject: test(vnode): tests for normlaizeVNode X-Git-Tag: v3.0.0-alpha.0~490 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e57d686b9ae1f175445211315089df773cce58c7;p=thirdparty%2Fvuejs%2Fcore.git test(vnode): tests for normlaizeVNode --- diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index dbcc1da328..b25494ee7e 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -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')