| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- import { E2E_TIMEOUT, setupPuppeteer } from './e2eUtils'
- import path from 'node:path'
- import { createApp, ref } from 'vue'
- describe('e2e: TransitionGroup', () => {
- const { page, html, nextFrame, timeout } = setupPuppeteer()
- const baseUrl = `file://${path.resolve(__dirname, './transition.html')}`
- const duration = process.env.CI ? 200 : 50
- const buffer = process.env.CI ? 20 : 5
- const htmlWhenTransitionStart = () =>
- page().evaluate(() => {
- ;(document.querySelector('#toggleBtn') as any)!.click()
- return Promise.resolve().then(() => {
- return document.querySelector('#container')!.innerHTML
- })
- })
- const transitionFinish = (time = duration) => timeout(time + buffer)
- beforeEach(async () => {
- await page().goto(baseUrl)
- await page().waitForSelector('#app')
- })
- test(
- 'enter',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => items.value.push('d', 'e')
- return { click, items }
- },
- }).mount('#app')
- })
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>`,
- )
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-from test-enter-active">d</div>` +
- `<div class="test test-enter-from test-enter-active">e</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-active test-enter-to">d</div>` +
- `<div class="test test-enter-active test-enter-to">e</div>`,
- )
- await transitionFinish()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test">d</div>` +
- `<div class="test">e</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- test(
- 'leave',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => (items.value = ['b'])
- return { click, items }
- },
- }).mount('#app')
- })
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>`,
- )
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test test-leave-from test-leave-active">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test test-leave-from test-leave-active">c</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test test-leave-active test-leave-to">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test test-leave-active test-leave-to">c</div>`,
- )
- await transitionFinish()
- expect(await html('#container')).toBe(`<div class="test">b</div>`)
- },
- E2E_TIMEOUT,
- )
- test(
- 'enter + leave',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => (items.value = ['b', 'c', 'd'])
- return { click, items }
- },
- }).mount('#app')
- })
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>`,
- )
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test test-leave-from test-leave-active">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-from test-enter-active">d</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test test-leave-active test-leave-to">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-active test-enter-to">d</div>`,
- )
- await transitionFinish()
- expect(await html('#container')).toBe(
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test">d</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- test(
- 'appear',
- async () => {
- const appearHtml = await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group appear
- appear-from-class="test-appear-from"
- appear-to-class="test-appear-to"
- appear-active-class="test-appear-active"
- name="test">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => items.value.push('d', 'e')
- return { click, items }
- },
- }).mount('#app')
- return Promise.resolve().then(() => {
- return document.querySelector('#container')!.innerHTML
- })
- })
- // appear
- expect(appearHtml).toBe(
- `<div class="test test-appear-from test-appear-active">a</div>` +
- `<div class="test test-appear-from test-appear-active">b</div>` +
- `<div class="test test-appear-from test-appear-active">c</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test test-appear-active test-appear-to">a</div>` +
- `<div class="test test-appear-active test-appear-to">b</div>` +
- `<div class="test test-appear-active test-appear-to">c</div>`,
- )
- await transitionFinish()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>`,
- )
- // enter
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-from test-enter-active">d</div>` +
- `<div class="test test-enter-from test-enter-active">e</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-active test-enter-to">d</div>` +
- `<div class="test test-enter-active test-enter-to">e</div>`,
- )
- await transitionFinish()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test">d</div>` +
- `<div class="test">e</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- test(
- 'move',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group name="group">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => (items.value = ['d', 'b', 'a'])
- return { click, items }
- },
- }).mount('#app')
- })
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>`,
- )
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test group-enter-from group-enter-active">d</div>` +
- `<div class="test">b</div>` +
- `<div class="test group-move" style="">a</div>` +
- `<div class="test group-leave-from group-leave-active group-move" style="">c</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test group-enter-active group-enter-to">d</div>` +
- `<div class="test">b</div>` +
- `<div class="test group-move" style="">a</div>` +
- `<div class="test group-leave-active group-move group-leave-to" style="">c</div>`,
- )
- await transitionFinish(duration * 2)
- expect(await html('#container')).toBe(
- `<div class="test">d</div>` +
- `<div class="test">b</div>` +
- `<div class="test" style="">a</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- test(
- 'move while entering',
- async () => {
- await page().evaluate(duration => {
- const { createApp, ref, onMounted } = (window as any).Vue
- createApp({
- template: `
- <transition-group name="toasts" tag="div" id="toasts">
- <div class="toast" v-for="toast in list" :key="toast.id">
- {{ toast.text }} #{{ toast.id }}
- </div>
- </transition-group>
- <button id="addBtn" @click="add">button</button>
- `,
- setup: () => {
- const list = ref([])
- let id = 0
- const add = () => {
- if (list.value.length > 3) {
- list.value.splice(0, 1)
- }
- list.value.push({
- id,
- type: 'error',
- text: 'Test message',
- })
- id++
- }
- onMounted(() => {
- const styleNode = document.createElement('style')
- styleNode.innerHTML = `
- #toasts {
- position: absolute;
- bottom: 0;
- left: 0;
- }
- #toasts > .toast {
- width: 150px;
- margin-bottom: 10px;
- height: 30px;
- color: white;
- background: black;
- }
- .toasts-leave-active {
- position: absolute;
- }
- .toasts-move { transition: transform ${duration}ms ease; }
- `
- document.body.appendChild(styleNode)
- })
- return { list, add }
- },
- }).mount('#app')
- }, duration)
- const overlapDelay = Math.max(10, Math.floor(duration / 2))
- const { midTop, finalTop } = await page().evaluate(
- ({ overlapDelay, duration, buffer }) => {
- ;(document.querySelector('#addBtn') as any)!.click()
- return new Promise<{ midTop: number; finalTop: number }>(resolve => {
- setTimeout(() => {
- ;(document.querySelector('#addBtn') as any)!.click()
- Promise.resolve().then(() => {
- const nodes = Array.from(
- document.querySelectorAll('#toasts .toast'),
- ) as HTMLElement[]
- const firstToast = nodes.find(node =>
- node.textContent?.includes('#0'),
- )
- const midTop = firstToast
- ? firstToast.getBoundingClientRect().top
- : NaN
- setTimeout(() => {
- const finalTop = firstToast
- ? firstToast.getBoundingClientRect().top
- : NaN
- resolve({ midTop, finalTop })
- }, duration + buffer)
- })
- }, overlapDelay)
- })
- },
- { overlapDelay, duration, buffer },
- )
- expect(midTop).toBeGreaterThan(finalTop)
- },
- E2E_TIMEOUT,
- )
- test(
- 'dynamic name',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group :name="name">
- <div v-for="item in items" :key="item" >{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- <button id="changeNameBtn" @click="changeName">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const name = ref('invalid')
- const click = () => (items.value = ['b', 'c', 'a'])
- const changeName = () => {
- name.value = 'group'
- items.value = ['a', 'b', 'c']
- }
- return { click, items, name, changeName }
- },
- }).mount('#app')
- })
- expect(await html('#container')).toBe(
- `<div>a</div>` + `<div>b</div>` + `<div>c</div>`,
- )
- // invalid name
- expect(await htmlWhenTransitionStart()).toBe(
- `<div>b</div>` + `<div>c</div>` + `<div>a</div>`,
- )
- // change name
- const moveHtml = await page().evaluate(() => {
- ;(document.querySelector('#changeNameBtn') as any).click()
- return Promise.resolve().then(() => {
- return document.querySelector('#container')!.innerHTML
- })
- })
- expect(moveHtml).toBe(
- `<div class="group-move" style="">a</div>` +
- `<div class="group-move" style="">b</div>` +
- `<div class="group-move" style="">c</div>`,
- )
- // not sure why but we just have to wait really long for this to
- // pass consistently :/
- await transitionFinish(duration * 4 + buffer)
- expect(await html('#container')).toBe(
- `<div class="" style="">a</div>` +
- `<div class="" style="">b</div>` +
- `<div class="" style="">c</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- test(
- 'events',
- async () => {
- const onLeaveSpy = vi.fn()
- const onEnterSpy = vi.fn()
- const onAppearSpy = vi.fn()
- const beforeLeaveSpy = vi.fn()
- const beforeEnterSpy = vi.fn()
- const beforeAppearSpy = vi.fn()
- const afterLeaveSpy = vi.fn()
- const afterEnterSpy = vi.fn()
- const afterAppearSpy = vi.fn()
- await page().exposeFunction('onLeaveSpy', onLeaveSpy)
- await page().exposeFunction('onEnterSpy', onEnterSpy)
- await page().exposeFunction('onAppearSpy', onAppearSpy)
- await page().exposeFunction('beforeLeaveSpy', beforeLeaveSpy)
- await page().exposeFunction('beforeEnterSpy', beforeEnterSpy)
- await page().exposeFunction('beforeAppearSpy', beforeAppearSpy)
- await page().exposeFunction('afterLeaveSpy', afterLeaveSpy)
- await page().exposeFunction('afterEnterSpy', afterEnterSpy)
- await page().exposeFunction('afterAppearSpy', afterAppearSpy)
- const appearHtml = await page().evaluate(() => {
- const {
- beforeAppearSpy,
- onAppearSpy,
- afterAppearSpy,
- beforeEnterSpy,
- onEnterSpy,
- afterEnterSpy,
- beforeLeaveSpy,
- onLeaveSpy,
- afterLeaveSpy,
- } = window as any
- const { createApp, ref } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <transition-group name="test"
- appear
- appear-from-class="test-appear-from"
- appear-to-class="test-appear-to"
- appear-active-class="test-appear-active"
- @before-enter="beforeEnterSpy()"
- @enter="onEnterSpy()"
- @after-enter="afterEnterSpy()"
- @before-leave="beforeLeaveSpy()"
- @leave="onLeaveSpy()"
- @after-leave="afterLeaveSpy()"
- @before-appear="beforeAppearSpy()"
- @appear="onAppearSpy()"
- @after-appear="afterAppearSpy()">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => (items.value = ['b', 'c', 'd'])
- return {
- click,
- items,
- beforeAppearSpy,
- onAppearSpy,
- afterAppearSpy,
- beforeEnterSpy,
- onEnterSpy,
- afterEnterSpy,
- beforeLeaveSpy,
- onLeaveSpy,
- afterLeaveSpy,
- }
- },
- }).mount('#app')
- return Promise.resolve().then(() => {
- return document.querySelector('#container')!.innerHTML
- })
- })
- expect(beforeAppearSpy).toBeCalled()
- expect(onAppearSpy).toBeCalled()
- expect(afterAppearSpy).not.toBeCalled()
- expect(appearHtml).toBe(
- `<div class="test test-appear-from test-appear-active">a</div>` +
- `<div class="test test-appear-from test-appear-active">b</div>` +
- `<div class="test test-appear-from test-appear-active">c</div>`,
- )
- await nextFrame()
- expect(afterAppearSpy).not.toBeCalled()
- expect(await html('#container')).toBe(
- `<div class="test test-appear-active test-appear-to">a</div>` +
- `<div class="test test-appear-active test-appear-to">b</div>` +
- `<div class="test test-appear-active test-appear-to">c</div>`,
- )
- await transitionFinish()
- expect(afterAppearSpy).toBeCalled()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>`,
- )
- // enter + leave
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test test-leave-from test-leave-active">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-from test-enter-active">d</div>`,
- )
- expect(beforeLeaveSpy).toBeCalled()
- expect(onLeaveSpy).toBeCalled()
- expect(afterLeaveSpy).not.toBeCalled()
- expect(beforeEnterSpy).toBeCalled()
- expect(onEnterSpy).toBeCalled()
- expect(afterEnterSpy).not.toBeCalled()
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test test-leave-active test-leave-to">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-active test-enter-to">d</div>`,
- )
- expect(afterLeaveSpy).not.toBeCalled()
- expect(afterEnterSpy).not.toBeCalled()
- await transitionFinish()
- expect(await html('#container')).toBe(
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test">d</div>`,
- )
- expect(afterLeaveSpy).toBeCalled()
- expect(afterEnterSpy).toBeCalled()
- },
- E2E_TIMEOUT,
- )
- test('warn unkeyed children', () => {
- createApp({
- template: `
- <transition-group name="test">
- <div v-for="item in items" class="test">{{item}}</div>
- </transition-group>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- return { items }
- },
- }).mount(document.createElement('div'))
- expect(`<TransitionGroup> children must be keyed`).toHaveBeenWarned()
- })
- test('not warn unkeyed text children w/ whitespace preserve', () => {
- const app = createApp({
- template: `
- <transition-group name="test">
- <p key="1">1</p>
- <p key="2" v-if="false">2</p>
- </transition-group>
- `,
- })
- app.config.compilerOptions.whitespace = 'preserve'
- app.mount(document.createElement('div'))
- expect(`<TransitionGroup> children must be keyed`).not.toHaveBeenWarned()
- })
- // #5168, #7898, #9067
- test(
- 'avoid set transition hooks for comment node',
- async () => {
- await page().evaluate(duration => {
- const { createApp, ref, h, createCommentVNode } = (window as any).Vue
- const show = ref(false)
- createApp({
- template: `
- <div id="container">
- <transition-group name="test">
- <div v-for="item in items" :key="item" class="test">{{item}}</div>
- <Child key="child"/>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- components: {
- Child: {
- setup() {
- return () =>
- show.value
- ? h('div', { class: 'test' }, 'child')
- : createCommentVNode('v-if', true)
- },
- },
- },
- setup: () => {
- const items = ref([])
- const click = () => {
- items.value = ['a', 'b', 'c']
- setTimeout(() => {
- show.value = true
- }, duration)
- }
- return { click, items }
- },
- }).mount('#app')
- }, duration)
- expect(await html('#container')).toBe(`<!--v-if-->`)
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test test-enter-from test-enter-active">a</div>` +
- `<div class="test test-enter-from test-enter-active">b</div>` +
- `<div class="test test-enter-from test-enter-active">c</div>` +
- `<!--v-if-->`,
- )
- await transitionFinish(duration)
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test test-enter-active test-enter-to">child</div>`,
- )
- await transitionFinish(duration)
- expect(await html('#container')).toBe(
- `<div class="test">a</div>` +
- `<div class="test">b</div>` +
- `<div class="test">c</div>` +
- `<div class="test">child</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- // #4621, #4622, #5153
- test(
- 'avoid set transition hooks for text node',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref } = (window as any).Vue
- const app = createApp({
- template: `
- <div id="container">
- <transition-group name="test">
- <div class="test">foo</div>
- <div class="test" v-if="show">bar</div>
- </transition-group>
- </div>
- <button id="toggleBtn" @click="click">button</button>
- `,
- setup: () => {
- const show = ref(false)
- const click = () => {
- show.value = true
- }
- return { show, click }
- },
- })
- app.config.compilerOptions.whitespace = 'preserve'
- app.mount('#app')
- })
- expect(await html('#container')).toBe(`<div class="test">foo</div>` + ` `)
- expect(await htmlWhenTransitionStart()).toBe(
- `<div class="test">foo</div>` +
- ` ` +
- `<div class="test test-enter-from test-enter-active">bar</div>`,
- )
- await nextFrame()
- expect(await html('#container')).toBe(
- `<div class="test">foo</div>` +
- ` ` +
- `<div class="test test-enter-active test-enter-to">bar</div>`,
- )
- await transitionFinish(duration)
- expect(await html('#container')).toBe(
- `<div class="test">foo</div>` + ` ` + `<div class="test">bar</div>`,
- )
- },
- E2E_TIMEOUT,
- )
- // #6105
- test(
- 'with scale',
- async () => {
- await page().evaluate(() => {
- const { createApp, ref, onMounted } = (window as any).Vue
- createApp({
- template: `
- <div id="container">
- <div class="scale" style="transform: scale(2) translateX(50%) translateY(50%)">
- <transition-group tag="ul">
- <li v-for="item in items" :key="item">{{item}}</li>
- </transition-group>
- <button id="toggleBtn" @click="click">button</button>
- </div>
- </div>
- `,
- setup: () => {
- const items = ref(['a', 'b', 'c'])
- const click = () => {
- items.value.reverse()
- }
- onMounted(() => {
- const styleNode = document.createElement('style')
- styleNode.innerHTML = `.v-move {
- transition: transform 0.5s ease;
- }`
- document.body.appendChild(styleNode)
- })
- return { items, click }
- },
- }).mount('#app')
- })
- const original_top = await page().$eval('ul li:nth-child(1)', node => {
- return node.getBoundingClientRect().top
- })
- const new_top = await page().evaluate(() => {
- const el = document.querySelector('ul li:nth-child(1)')
- const p = new Promise(resolve => {
- el!.addEventListener('transitionstart', () => {
- const new_top = el!.getBoundingClientRect().top
- resolve(new_top)
- })
- })
- ;(document.querySelector('#toggleBtn') as any)!.click()
- return p
- })
- expect(original_top).toBeLessThan(new_top as number)
- },
- E2E_TIMEOUT,
- )
- test(
- 'not leaking after children unmounted',
- async () => {
- const client = await page().createCDPSession()
- await page().evaluate(async () => {
- const { createApp, ref, nextTick } = (window as any).Vue
- const show = ref(true)
- createApp({
- components: {
- Child: {
- setup: () => {
- // Big arrays kick GC earlier
- const test = ref([...Array(3000)].map((_, i) => ({ i })))
- // @ts-expect-error - Custom property and same lib as runtime is used
- window.__REF__ = new WeakRef(test)
- return { test }
- },
- template: `
- <p>{{ test.length }}</p>
- `,
- },
- },
- template: `
- <transition-group>
- <Child v-if="show" />
- </transition-group>
- `,
- setup() {
- return { show }
- },
- }).mount('#app')
- show.value = false
- await nextTick()
- })
- const isCollected = async () =>
- // @ts-expect-error - Custom property
- await page().evaluate(() => window.__REF__.deref() === undefined)
- while ((await isCollected()) === false) {
- await client.send('HeapProfiler.collectGarbage')
- }
- expect(await isCollected()).toBe(true)
- },
- E2E_TIMEOUT,
- )
- })
|