From a7ef59c4c3b4dc0aa1e17a3b983258bb7cd66de3 Mon Sep 17 00:00:00 2001 From: likui <2218301630@qq.com> Date: Tue, 31 Dec 2019 00:25:44 +0800 Subject: [PATCH] test(vnode): add test for dynamic children (#563) --- packages/runtime-core/__tests__/vnode.spec.ts | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/vnode.spec.ts b/packages/runtime-core/__tests__/vnode.spec.ts index beefbe55..934b0952 100644 --- a/packages/runtime-core/__tests__/vnode.spec.ts +++ b/packages/runtime-core/__tests__/vnode.spec.ts @@ -1,4 +1,4 @@ -import { createVNode } from '@vue/runtime-test' +import { createBlock, createVNode, openBlock } from '@vue/runtime-test' import { ShapeFlags, Comment, @@ -225,4 +225,34 @@ describe('vnode', () => { }) }) }) + + describe('dynamic children', () => { + test('single call openBlock', () => { + const hoist = createVNode('div') + let vnode1 + const vnode = (openBlock(), + createBlock('div', null, [ + hoist, + (vnode1 = createVNode('div', null, 'text', 1 /* TEXT */)) + ])) + expect(vnode.dynamicChildren).toStrictEqual([vnode1]) + }) + + test('many times call openBlock', () => { + const hoist = createVNode('div') + let vnode1, vnode2, vnode3 + const vnode = (openBlock(), + createBlock('div', null, [ + hoist, + (vnode1 = createVNode('div', null, 'text', 1 /* TEXT */)), + (vnode2 = (openBlock(), + createBlock('div', null, [ + hoist, + (vnode3 = createVNode('div', null, 'text', 1 /* TEXT */)) + ]))) + ])) + expect(vnode.dynamicChildren).toStrictEqual([vnode1, vnode2]) + expect(vnode2.dynamicChildren).toStrictEqual([vnode3]) + }) + }) })