Skip to content

Commit c9f53cc

Browse files
committed
test: add test case
1 parent f435e19 commit c9f53cc

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

packages/vue/__tests__/e2e/Transition.spec.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,76 @@ describe('e2e: Transition', () => {
14981498
},
14991499
E2E_TIMEOUT
15001500
)
1501+
1502+
test(
1503+
'avoid unmount activeBranch twice with Suspense (out-in mode + timeout="0")',
1504+
async () => {
1505+
const unmountSpy = vi.fn()
1506+
1507+
await page().exposeFunction('unmountSpy', unmountSpy)
1508+
1509+
await page().evaluate(() => {
1510+
const { createApp, shallowRef, h } = (window as any).Vue
1511+
const One = {
1512+
setup() {
1513+
return () =>
1514+
h(
1515+
'div',
1516+
{
1517+
onVnodeBeforeUnmount: () => unmountSpy()
1518+
},
1519+
'one'
1520+
)
1521+
}
1522+
}
1523+
const Two = {
1524+
async setup() {
1525+
return () => h('div', null, 'two')
1526+
}
1527+
}
1528+
createApp({
1529+
template: `
1530+
<div id="container">
1531+
<transition mode="out-in">
1532+
<suspense timeout="0">
1533+
<template #default>
1534+
<component :is="view"></component>
1535+
</template>
1536+
<template #fallback>
1537+
<div>Loading...</div>
1538+
</template>
1539+
</suspense>
1540+
</transition>
1541+
</div>
1542+
<button id="toggleBtn" @click="click">button</button>
1543+
`,
1544+
setup: () => {
1545+
const view = shallowRef(One)
1546+
const click = () => {
1547+
view.value = view.value === One ? Two : One
1548+
}
1549+
return { view, click }
1550+
}
1551+
}).mount('#app')
1552+
})
1553+
1554+
expect(await html('#container')).toBe('<div>one</div>')
1555+
1556+
// leave
1557+
await classWhenTransitionStart()
1558+
await nextFrame()
1559+
expect(await html('#container')).toBe(
1560+
'<div class="v-enter-from v-enter-active">two</div>'
1561+
)
1562+
1563+
await transitionFinish()
1564+
expect(await html('#container')).toBe('<div class="">two</div>')
1565+
1566+
// should only call unmount once
1567+
expect(unmountSpy).toBeCalledTimes(1)
1568+
},
1569+
E2E_TIMEOUT
1570+
)
15011571
})
15021572

15031573
describe('transition with v-show', () => {

0 commit comments

Comments
 (0)