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

navigation.spec.ts

90 lines3.1 KB

1import { expect } from '@playwright/test'
2​
3import { test } from '@tanstack/router-e2e-utils'
4​
5test.use({
6 whitelistErrors: [
7 'Failed to load resource: the server responded with a status of 404',
8 ],
9})
10test('Navigating to post', async ({ page }) => {
11 await page.goto('/')
12 await page.waitForURL('/')
13​
14 await page.getByRole('link', { name: 'Posts' }).click()
15 await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
16 await page.getByRole('link', { name: 'Deep View' }).click()
17 await expect(page.getByRole('heading')).toContainText('sunt aut facere')
18})
19​
20test('plain .ts modules with angle-bracket type assertions build and render', async ({
21 page,
22}) => {
23 await page.goto('/plain-ts-type-assertion')
24 await expect(page.getByTestId('plain-ts-parser-regression')).toContainText(
25 'plain .ts cast parsed',
26 )
27})
28​
29test('Navigating to user', async ({ page }) => {
30 await page.goto('/')
31 await page.waitForURL('/')
32 await page.getByRole('link', { name: 'Users' }).click()
33 await page.getByRole('link', { name: 'Leanne Graham' }).click()
34 await expect(page.getByRole('heading')).toContainText('Leanne Graham')
35})
36​
37test('Navigating nested layouts', async ({ page }) => {
38 await page.goto('/')
39 await page.waitForURL('/')
40​
41 await page.getByRole('link', { name: 'Layout', exact: true }).click()
42 await page.waitForURL('/layout-a')
43​
44 await expect(page.locator('body')).toContainText("I'm a layout")
45 await expect(page.locator('body')).toContainText("I'm a nested layout")
46 await expect(page.locator('body')).toContainText("I'm layout A!")
47​
48 await page.getByRole('link', { name: 'Layout B' }).click()
49 await page.waitForURL('/layout-b')
50 await expect(page.locator('body')).toContainText("I'm layout B!")
51​
52 await page.getByRole('link', { name: 'Layout A' }).click()
53 await page.waitForURL('/layout-a')
54 await expect(page.locator('body')).toContainText("I'm layout A!")
55})
56​
57test('client side navigating to a route with scripts', async ({ page }) => {
58 await page.goto('/')
59 await page.waitForURL('/')
60 await page.getByRole('link', { name: 'Scripts', exact: true }).click()
61 await expect(page.getByTestId('scripts-test-heading')).toBeInViewport()
62 await page.waitForFunction(() => (window as any).SCRIPT_1 === true)
63 expect(await page.evaluate('window.SCRIPT_2')).toBe(undefined)
64})
65​
66test('directly going to a route with scripts', async ({ page }) => {
67 await page.goto('/scripts')
68 await page.waitForURL('/scripts')
69 await page.waitForLoadState('networkidle')
70 await page.waitForFunction(() => (window as any).SCRIPT_1 === true)
71 expect(await page.evaluate('window.SCRIPT_2')).toBe(undefined)
72})
73​
74test('Navigating to a not-found route', async ({ page }) => {
75 await page.goto('/')
76 await page.waitForURL('/')
77​
78 await page.getByRole('link', { name: 'This Route Does Not Exist' }).click()
79 await page.getByRole('link', { name: 'Start Over' }).click()
80 await expect(page.getByRole('heading')).toContainText('Welcome Home!')
81})
82​
83test('Should change title on client side navigation', async ({ page }) => {
84 await page.goto('/')
85 await page.waitForURL('/')
86​
87 await page.getByRole('link', { name: 'Posts' }).click()
88​
89 await expect(page).toHaveTitle('Posts page')
90})