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 Dec 14, 2023
1 parent 458e880 commit a1de64a
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions packages/vue/__tests__/e2e/Transition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,95 @@ describe('e2e: Transition', () => {
)
})

describe('transition with Teleport', () => {
test(
'apply transition to teleport child',
async () => {
await page().evaluate(() => {
const { createApp, ref, h } = (window as any).Vue
createApp({
template: `
<div id="target"></div>
<div id="container">
<transition>
<Teleport to="#target">
<!-- comment -->
<Comp v-if="toggle" class="test">content</Comp>
</Teleport>
</transition>
</div>
<button id="toggleBtn" @click="click">button</button>
`,
components: {
Comp: {
setup() {
return () => h('div', { class: 'test' }, 'content')
}
}
},
setup: () => {
const toggle = ref(false)
const click = () => (toggle.value = !toggle.value)
return { toggle, click }
}
}).mount('#app')
})

expect(await html('#target')).toBe('<!-- comment --><!--v-if-->')
expect(await html('#container')).toBe(
'<!--teleport start--><!--teleport end-->'
)

const classWhenTransitionStart = () =>
page().evaluate(() => {
;(document.querySelector('#toggleBtn') as any)!.click()
return Promise.resolve().then(() => {
// find the class of teleported node
return document
.querySelector('#target div')!
.className.split(/\s+/g)
})
})

// enter
expect(await classWhenTransitionStart()).toStrictEqual([
'test',
'v-enter-from',
'v-enter-active'
])
await nextFrame()
expect(await classList('.test')).toStrictEqual([
'test',
'v-enter-active',
'v-enter-to'
])
await transitionFinish()
expect(await html('#target')).toBe(
'<!-- comment --><div class="test">content</div>'
)

// leave
expect(await classWhenTransitionStart()).toStrictEqual([
'test',
'v-leave-from',
'v-leave-active'
])
await nextFrame()
expect(await classList('.test')).toStrictEqual([
'test',
'v-leave-active',
'v-leave-to'
])
await transitionFinish()
expect(await html('#target')).toBe('<!-- comment --><!--v-if-->')
expect(await html('#container')).toBe(
'<!--teleport start--><!--teleport end-->'
)
},
E2E_TIMEOUT
)
})

describe('transition with v-show', () => {
test(
'named transition with v-show',
Expand Down

0 comments on commit a1de64a

Please sign in to comment.