|
1 | 1 | import { E2E_TIMEOUT, setupPuppeteer } from '../e2eUtils'
|
2 | 2 | import path from 'path'
|
3 | 3 |
|
4 |
| -function nextFrame(cb: () => void) { |
5 |
| - requestAnimationFrame(() => { |
6 |
| - requestAnimationFrame(cb) |
7 |
| - }) |
8 |
| -} |
9 |
| - |
10 | 4 | describe('e2e: Transition', () => {
|
11 |
| - const { page, html, click, classList } = setupPuppeteer() |
| 5 | + const { page, html, classList } = setupPuppeteer() |
12 | 6 | const baseUrl = `file://${path.resolve(
|
13 | 7 | __dirname,
|
14 | 8 | '../../transition/index.html'
|
15 | 9 | )}`
|
16 |
| - const duration = 50, |
17 |
| - buffer = 10 |
| 10 | + |
18 | 11 | const container = '#test'
|
19 | 12 |
|
| 13 | + const duration = 50 |
| 14 | + const buffer = 10 |
| 15 | + const transitionFinish = () => |
| 16 | + new Promise(r => { |
| 17 | + setTimeout(r, duration + buffer) |
| 18 | + }) |
| 19 | + |
| 20 | + const nextFrame = () => { |
| 21 | + return page().evaluate(() => { |
| 22 | + return new Promise(resolve => { |
| 23 | + requestAnimationFrame(() => { |
| 24 | + requestAnimationFrame(resolve) |
| 25 | + }) |
| 26 | + }) |
| 27 | + }) |
| 28 | + } |
| 29 | + |
20 | 30 | test(
|
21 | 31 | 'basic transition',
|
22 | 32 | async () => {
|
23 | 33 | await page().goto(baseUrl)
|
24 | 34 | await page().waitFor('#app')
|
25 |
| - expect(await html(container)).toBe('<div class="test"></div>') |
| 35 | + expect(await html(container)).toBe('<div class="test">content</div>') |
26 | 36 |
|
27 |
| - await click('button') |
28 |
| - expect(await classList('#test div')).toStrictEqual([ |
| 37 | + const leaveStartClasses = await page().evaluate(() => { |
| 38 | + document.querySelector('button')!.click() |
| 39 | + return Promise.resolve().then(() => { |
| 40 | + return document.querySelector('#test div')!.className.split(/\s+/g) |
| 41 | + }) |
| 42 | + }) |
| 43 | + |
| 44 | + expect(leaveStartClasses).toStrictEqual([ |
29 | 45 | 'test',
|
30 | 46 | 'v-leave-active',
|
31 | 47 | 'v-leave-from'
|
32 | 48 | ])
|
33 |
| - await new Promise((resolve, reject) => { |
34 |
| - nextFrame(async () => { |
35 |
| - expect(await classList('#test div')).toStrictEqual([ |
36 |
| - 'test', |
37 |
| - 'v-leave-active', |
38 |
| - 'v-leave-to' |
39 |
| - ]) |
40 |
| - setTimeout(async () => { |
41 |
| - expect(await html('#test')).toBe('<!--v-if-->') |
42 |
| - resolve() |
43 |
| - }, duration + buffer) |
| 49 | + |
| 50 | + await nextFrame() |
| 51 | + expect(await classList('#test div')).toStrictEqual([ |
| 52 | + 'test', |
| 53 | + 'v-leave-active', |
| 54 | + 'v-leave-to' |
| 55 | + ]) |
| 56 | + |
| 57 | + await transitionFinish() |
| 58 | + expect(await html('#test')).toBe('<!--v-if-->') |
| 59 | + |
| 60 | + const enterStartClasses = await page().evaluate(() => { |
| 61 | + document.querySelector('button')!.click() |
| 62 | + return Promise.resolve().then(() => { |
| 63 | + return document.querySelector('#test div')!.className.split(/\s+/g) |
44 | 64 | })
|
45 | 65 | })
|
46 | 66 |
|
47 |
| - await click('button') |
48 |
| - expect(await classList('#test div')).toStrictEqual([ |
| 67 | + expect(enterStartClasses).toStrictEqual([ |
49 | 68 | 'test',
|
50 | 69 | 'v-enter-active',
|
51 | 70 | 'v-enter-from'
|
52 | 71 | ])
|
53 |
| - await new Promise((resolve, reject) => { |
54 |
| - nextFrame(async () => { |
55 |
| - expect(await classList('#test div')).toStrictEqual([ |
56 |
| - 'test', |
57 |
| - 'v-enter-active', |
58 |
| - 'v-enter-to' |
59 |
| - ]) |
60 |
| - setTimeout(async () => { |
61 |
| - expect(await html('#test')).toBe('<div class="test"></div>') |
62 |
| - resolve() |
63 |
| - }, duration + buffer) |
64 |
| - }) |
65 |
| - }) |
| 72 | + |
| 73 | + await nextFrame() |
| 74 | + expect(await classList('#test div')).toStrictEqual([ |
| 75 | + 'test', |
| 76 | + 'v-enter-active', |
| 77 | + 'v-enter-to' |
| 78 | + ]) |
| 79 | + |
| 80 | + await transitionFinish() |
| 81 | + expect(await html('#test')).toBe('<div class="test">content</div>') |
66 | 82 | },
|
67 | 83 | E2E_TIMEOUT
|
68 | 84 | )
|
|
0 commit comments