Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

transition.spec.ts

95 lines2.6 KB

1import { expect, test } from '@playwright/test'
2​
3test('transitions/count/query should keep old values visible during navigation', async ({
4 page,
5}) => {
6 await page.goto('/transition/count/query')
7​
8 await expect(page.getByTestId('n-value')).toContainText('n: 1')
9 await expect(page.getByTestId('double-value')).toContainText('double: 2')
10​
11 const bodyTexts: Array<string> = []
12​
13 const pollInterval = setInterval(async () => {
14 const text = await page
15 .locator('body')
16 .textContent()
17 .catch(() => '')
18 if (text) bodyTexts.push(text)
19 }, 50)
20​
21 // 1 click
22​
23 page.getByTestId('increase-button').click()
24​
25 await expect(page.getByTestId('n-value')).toContainText('n: 1', {
26 timeout: 2_000,
27 })
28 await expect(page.getByTestId('double-value')).toContainText('double: 2', {
29 timeout: 2_000,
30 })
31​
32 await page.waitForTimeout(200)
33​
34 await expect(page.getByTestId('n-value')).toContainText('n: 2', {
35 timeout: 2000,
36 })
37 await expect(page.getByTestId('double-value')).toContainText('double: 4', {
38 timeout: 2000,
39 })
40​
41 // 2 clicks
42​
43 // page.getByTestId('increase-button').click()
44 // page.getByTestId('increase-button').click()
45​
46 // await expect(page.getByTestId('n-value')).toContainText('n: 2', {
47 // timeout: 2000,
48 // })
49 // await expect(page.getByTestId('double-value')).toContainText('double: 4', {
50 // timeout: 2000,
51 // })
52​
53 // await page.waitForTimeout(200)
54​
55 // await expect(page.getByTestId('n-value')).toContainText('n: 4', {
56 // timeout: 2000,
57 // })
58 // await expect(page.getByTestId('double-value')).toContainText('double: 8', {
59 // timeout: 2000,
60 // })
61​
62 // // 3 clicks
63​
64 // page.getByTestId('increase-button').click()
65 // page.getByTestId('increase-button').click()
66 // page.getByTestId('increase-button').click()
67​
68 // await expect(page.getByTestId('n-value')).toContainText('n: 4', {
69 // timeout: 2000,
70 // })
71 // await expect(page.getByTestId('double-value')).toContainText('double: 8', {
72 // timeout: 2000,
73 // })
74​
75 // await page.waitForTimeout(200)
76​
77 // await expect(page.getByTestId('n-value')).toContainText('n: 7', {
78 // timeout: 2000,
79 // })
80 // await expect(page.getByTestId('double-value')).toContainText('double: 14', {
81 // timeout: 2000,
82 // })
83​
84 clearInterval(pollInterval)
85​
86 // With proper transitions, old values should remain visible until new ones arrive
87 const hasLoadingText = bodyTexts.some((text) => text.includes('Loading...'))
88​
89 if (hasLoadingText) {
90 throw new Error(
91 'FAILED: "Loading..." appeared during navigation. ' +
92 'Solid Router should use transitions to keep old values visible.',
93 )
94 }
95})