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

transition.spec.ts

96 lines2.6 KB

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