Open History to see the last commit
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β
13 await page.getByRole('link', { name: 'Posts' }).click()
14 await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
15 await page.getByRole('link', { name: 'Deep View' }).click()
16 await expect(page.getByRole('heading')).toContainText('sunt aut facere')
17})
18β
19test('Navigating to user', async ({ page }) => {
20 await page.goto('/')
21 await page.waitForURL('/')
22 await page.getByRole('link', { name: 'Users' }).click()
23 await page.getByRole('link', { name: 'Leanne Graham' }).click()
24 await expect(page.getByRole('heading')).toContainText('Leanne Graham')
25})
26β
27test('Navigating nested layouts', async ({ page }) => {
28 await page.goto('/')
29 await page.waitForURL('/')
30β
31 await page.getByRole('link', { name: 'Layout', exact: true }).click()
32β
33 await expect(page.locator('body')).toContainText("I'm a layout")
34 await expect(page.locator('body')).toContainText("I'm a nested layout")
35β
36 await page.getByRole('link', { name: 'Layout A' }).click()
37 await expect(page.locator('body')).toContainText("I'm layout A!")
38β
39 await page.getByRole('link', { name: 'Layout B' }).click()
40 await expect(page.locator('body')).toContainText("I'm layout B!")
41})
42β
43test('client side navigating to a route with scripts', async ({ page }) => {
44 await page.goto('/')
45 await page.waitForURL('/')
46 await page.getByRole('link', { name: 'Scripts', exact: true }).click()
47 await expect(page.getByTestId('scripts-test-heading')).toBeInViewport()
48 expect(await page.evaluate('window.SCRIPT_1')).toBe(true)
49 expect(await page.evaluate('window.SCRIPT_2')).toBe(undefined)
50})
51β
52test('directly going to a route with scripts', async ({ page }) => {
53 await page.goto('/scripts')
54 await page.waitForURL('/scripts')
55 await page.waitForLoadState('networkidle')
56 expect(await page.evaluate('window.SCRIPT_1')).toBe(true)
57 expect(await page.evaluate('window.SCRIPT_2')).toBe(undefined)
58})
59β
60test('Navigating to a not-found route', async ({ page }) => {
61 await page.goto('/')
62 await page.waitForURL('/')
63β
64 await page.getByRole('link', { name: 'This Route Does Not Exist' }).click()
65 await page.getByRole('link', { name: 'Start Over' }).click()
66 await expect(page.getByRole('heading')).toContainText('Welcome Home!')
67})
68β
69test('Should change title on client side navigation', async ({ page }) => {
70 await page.goto('/')
71 await page.waitForURL('/')
72β
73 await page.getByRole('link', { name: 'Posts' }).click()
74β
75 await expect(page).toHaveTitle('Posts page')
76})