From 1373bc7c05ee5db799a0da20819304f5398d743c Mon Sep 17 00:00:00 2001 From: daiwei Date: Wed, 15 Jan 2025 13:57:18 +0800 Subject: [PATCH] test: add test case --- .../__tests__/helpers/withMemo.spec.ts | 26 +++++++++++++++++++ packages/runtime-core/src/vnode.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts index 32f89b1d8e9..cc447327e39 100644 --- a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts +++ b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts @@ -204,6 +204,32 @@ describe('v-memo', () => { ) }) + // #12708 + test('v-memo should work correctly when toggling v-if with v-for inside', async () => { + const [el, vm] = mount({ + template: ` + {{count}} + `, + data: () => ({ + show: true, + count: 0, + }), + }) + expect(el.innerHTML).toBe(`0`) + + vm.show = false + await nextTick() + expect(el.innerHTML).toBe(``) + + vm.show = true + await nextTick() + expect(el.innerHTML).toBe(`0`) + + vm.count++ + await nextTick() + expect(el.innerHTML).toBe(`1`) + }) + test('on v-for /w constant expression ', async () => { const [el, vm] = mount({ template: `
diff --git a/packages/runtime-core/src/vnode.ts b/packages/runtime-core/src/vnode.ts index 97a9e8b234b..34aea8f79cb 100644 --- a/packages/runtime-core/src/vnode.ts +++ b/packages/runtime-core/src/vnode.ts @@ -243,7 +243,7 @@ export interface VNode< memo?: any[] /** * @internal index for cleaning v-memo cache - * cacheIndex will be an array when vnode in vFor + * cacheIndex will be an array when vnode in vFor + vMemo */ cacheIndex?: number | number[] /**