Skip to content

Commit

Permalink
test(transition): refactor DOM transition test
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 11, 2020
1 parent 66c5a55 commit 9d111f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 40 deletions.
92 changes: 54 additions & 38 deletions packages/vue/examples/__tests__/transition/Transition.spec.ts
Original file line number Diff line number Diff line change
@@ -1,68 +1,84 @@
import { E2E_TIMEOUT, setupPuppeteer } from '../e2eUtils'
import path from 'path'

function nextFrame(cb: () => void) {
requestAnimationFrame(() => {
requestAnimationFrame(cb)
})
}

describe('e2e: Transition', () => {
const { page, html, click, classList } = setupPuppeteer()
const { page, html, classList } = setupPuppeteer()
const baseUrl = `file://${path.resolve(
__dirname,
'../../transition/index.html'
)}`
const duration = 50,
buffer = 10

const container = '#test'

const duration = 50
const buffer = 10
const transitionFinish = () =>
new Promise(r => {
setTimeout(r, duration + buffer)
})

const nextFrame = () => {
return page().evaluate(() => {
return new Promise(resolve => {
requestAnimationFrame(() => {
requestAnimationFrame(resolve)
})
})
})
}

test(
'basic transition',
async () => {
await page().goto(baseUrl)
await page().waitFor('#app')
expect(await html(container)).toBe('<div class="test"></div>')
expect(await html(container)).toBe('<div class="test">content</div>')

await click('button')
expect(await classList('#test div')).toStrictEqual([
const leaveStartClasses = await page().evaluate(() => {
document.querySelector('button')!.click()
return Promise.resolve().then(() => {
return document.querySelector('#test div')!.className.split(/\s+/g)
})
})

expect(leaveStartClasses).toStrictEqual([
'test',
'v-leave-active',
'v-leave-from'
])
await new Promise((resolve, reject) => {
nextFrame(async () => {
expect(await classList('#test div')).toStrictEqual([
'test',
'v-leave-active',
'v-leave-to'
])
setTimeout(async () => {
expect(await html('#test')).toBe('<!--v-if-->')
resolve()
}, duration + buffer)

await nextFrame()
expect(await classList('#test div')).toStrictEqual([
'test',
'v-leave-active',
'v-leave-to'
])

await transitionFinish()
expect(await html('#test')).toBe('<!--v-if-->')

const enterStartClasses = await page().evaluate(() => {
document.querySelector('button')!.click()
return Promise.resolve().then(() => {
return document.querySelector('#test div')!.className.split(/\s+/g)
})
})

await click('button')
expect(await classList('#test div')).toStrictEqual([
expect(enterStartClasses).toStrictEqual([
'test',
'v-enter-active',
'v-enter-from'
])
await new Promise((resolve, reject) => {
nextFrame(async () => {
expect(await classList('#test div')).toStrictEqual([
'test',
'v-enter-active',
'v-enter-to'
])
setTimeout(async () => {
expect(await html('#test')).toBe('<div class="test"></div>')
resolve()
}, duration + buffer)
})
})

await nextFrame()
expect(await classList('#test div')).toStrictEqual([
'test',
'v-enter-active',
'v-enter-to'
])

await transitionFinish()
expect(await html('#test')).toBe('<div class="test">content</div>')
},
E2E_TIMEOUT
)
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/examples/transition/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<script>
Vue.createApp({
template: `
<div id="test"><transition><div v-if="toggle" class="test"></div></transition></div>
<button @click="click"></button>
<div id="test"><transition><div v-if="toggle" class="test">content</div></transition></div>
<button @click="click">button</button>
`,
setup:() => {
const toggle = Vue.ref(true)
Expand Down

0 comments on commit 9d111f5

Please sign in to comment.