Open History to see the last commit
1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3import type { Page } from '@playwright/test'
4β
5async function runTest(
6 page: Page,
7 expectedData: {
8 root: 'server' | 'client'
9 posts: 'server' | 'client'
10 postId: 'server' | 'client'
11 },
12) {
13 // wait for page to be loaded by waiting for the leaf route to be rendered
14 await expect(page.getByTestId('postId-heading')).toContainText('postId')
15β
16 // check expectations
17 await Promise.all(
18 Object.entries(expectedData).map(async ([route, expectedData]) => {
19 await expect(page.getByTestId(`${route}-loader`)).toContainText(
20 expectedData,
21 )
22 await expect(page.getByTestId(`${route}-context`)).toContainText(
23 expectedData,
24 )
25 }),
26 )
27 await expect(page.getByTestId('router-isLoading')).toContainText('false')
28 await expect(page.getByTestId('router-status')).toContainText('idle')
29}
30test.describe('SPA mode', () => {
31 test(`directly visiting prerendered /posts/1`, async ({ page }) => {
32 await page.goto('/posts/1')
33 await runTest(page, {
34 root: 'server',
35 posts: 'server',
36 postId: 'server',
37 })
38 })
39β
40 test(`client-side navigation to /posts/1`, async ({ page }) => {
41 await page.goto('/')
42 const testId = 'link-posts-1'
43 await page.getByTestId(testId).click()
44 await runTest(page, {
45 root: 'client',
46 posts: 'client',
47 postId: 'client',
48 })
49 })
50})