test: add test case

This commit is contained in:
daiwei 2025-01-15 13:57:18 +08:00
parent b6a78a4d87
commit 1373bc7c05
2 changed files with 27 additions and 1 deletions

View File

@ -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]">

View File

@ -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[]
/**