From f6db1f544c59f97d198a25396b238478fe0fdd79 Mon Sep 17 00:00:00 2001 From: likui <2218301630@qq.com> Date: Sat, 25 Jul 2020 20:41:24 +0800 Subject: [PATCH] fix: add test --- .../__tests__/components/Teleport.spec.ts | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/components/Teleport.spec.ts b/packages/runtime-core/__tests__/components/Teleport.spec.ts index 99bea073072..c3d02244c8f 100644 --- a/packages/runtime-core/__tests__/components/Teleport.spec.ts +++ b/packages/runtime-core/__tests__/components/Teleport.spec.ts @@ -6,9 +6,12 @@ import { Teleport, Text, ref, - nextTick + nextTick, + openBlock, + createBlock } from '@vue/runtime-test' import { createVNode, Fragment } from '../../src/vnode' +import { PatchFlags } from '@vue/shared' describe('renderer: teleport', () => { test('should work', () => { @@ -299,4 +302,55 @@ describe('renderer: teleport', () => { ) expect(serializeInner(target)).toBe('') }) + + test('should work with block tree', async () => { + const target = nodeOps.createElement('div') + const root = nodeOps.createElement('div') + const disabled = ref(false) + + const App = { + render() { + return ( + openBlock(), + createBlock( + Fragment, + null, + [ + h( + Teleport, + { to: target, disabled: disabled.value }, + h('div', 'teleported') + ), + h('div', 'root') + ], + PatchFlags.STABLE_FRAGMENT + ) + ) + } + } + render(h(App), root) + expect(serializeInner(root)).toMatchInlineSnapshot( + `"
root
"` + ) + expect(serializeInner(target)).toMatchInlineSnapshot( + `"
teleported
"` + ) + + disabled.value = true + await nextTick() + expect(serializeInner(root)).toMatchInlineSnapshot( + `"
teleported
root
"` + ) + expect(serializeInner(target)).toBe(``) + + // toggle back + disabled.value = false + await nextTick() + expect(serializeInner(root)).toMatchInlineSnapshot( + `"
root
"` + ) + expect(serializeInner(target)).toMatchInlineSnapshot( + `"
teleported
"` + ) + }) })