Open History to see the last commit
1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3β
4test.use({
5 whitelistErrors: [
6 'Failed to load resource: the server responded with a status of 404',
7 ],
8})
9test('Navigating to post', async ({ page }) => {
10 await page.goto('/')
11β
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('Navigating to user', async ({ page }) => {
21 await page.goto('/')
22β
23 await page.waitForURL('/')
24β
25 await page.getByRole('link', { name: 'Users' }).click()
26 await page.getByRole('link', { name: 'Leanne Graham' }).click()
27 await expect(page.getByRole('heading')).toContainText('Leanne Graham')
28})
29β
30test('Navigating nested layouts', async ({ page }) => {
31 await page.goto('/')
32β
33 await page.waitForURL('/')
34β
35 await page.getByRole('link', { name: 'Layout', exact: true }).click()
36β
37 await expect(page.locator('body')).toContainText("I'm a layout")
38 await expect(page.locator('body')).toContainText("I'm a nested layout")
39β
40 await page.getByRole('link', { name: 'Layout A' }).click()
41 await expect(page.locator('body')).toContainText("I'm layout A!")
42β
43 await page.getByRole('link', { name: 'Layout B' }).click()
44 await expect(page.locator('body')).toContainText("I'm layout B!")
45})
46β
47test('client side navigating to a route with scripts', async ({ page }) => {
48 await page.goto('/')
49β
50 await page.waitForURL('/')
51 await page.getByRole('link', { name: 'Scripts', exact: true }).click()
52 await expect(page.getByTestId('scripts-test-heading')).toBeInViewport()
53 await page.waitForFunction(() => (window as any).SCRIPT_1 === true)
54 expect(await page.evaluate('window.SCRIPT_2')).toBe(undefined)
55})
56β
57test('directly going to a route with scripts', async ({ page }) => {
58 await page.goto('/scripts')
59β
60 await page.waitForURL('/scripts')
61 await page.waitForLoadState('networkidle')
62 expect(await page.evaluate('window.SCRIPT_1')).toBe(true)
63 expect(await page.evaluate('window.SCRIPT_2')).toBe(undefined)
64})
65β
66test('Navigating to a not-found route', async ({ page }) => {
67 await page.goto('/')
68β
69 await page.waitForURL('/')
70β
71 await page.getByRole('link', { name: 'This Route Does Not Exist' }).click()
72 await page.getByRole('link', { name: 'Start Over' }).click()
73 await expect(page.getByRole('heading')).toContainText('Welcome Home!')
74})
75β
76test('Should change title on client side navigation', async ({ page }) => {
77 await page.goto('/')
78β
79 await page.waitForURL('/')
80β
81 await page.getByRole('link', { name: 'Posts' }).click()
82β
83 await expect(page).toHaveTitle('Posts page')
84})