Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Jan 15, 2025
1 parent b6a78a4 commit 1373bc7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/runtime-core/__tests__/helpers/withMemo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<span v-if="show">
<span v-for="elem in [1]" :key="elem" v-memo="[count]">{{count}}</span>
</span>`,
data: () => ({
show: true,
count: 0,
}),
})
expect(el.innerHTML).toBe(`<span><span>0</span></span>`)

vm.show = false
await nextTick()
expect(el.innerHTML).toBe(`<!--v-if-->`)

vm.show = true
await nextTick()
expect(el.innerHTML).toBe(`<span><span>0</span></span>`)

vm.count++
await nextTick()
expect(el.innerHTML).toBe(`<span><span>1</span></span>`)
})

test('on v-for /w constant expression ', async () => {
const [el, vm] = mount({
template: `<div v-for="item in 3" v-memo="[count < 2 ? true : count]">
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
/**
Expand Down

0 comments on commit 1373bc7

Please sign in to comment.