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

app.spec.ts

63 lines2.4 KB

1import { expect } from '@playwright/test'
2import { apiTest as test } from '@tanstack/router-e2e-utils'
3​
4const PORT = Number(process.env.E2E_APP_PORT ?? 0)
5​
6test.beforeEach(async ({ page }) => {
7 await page.goto('/')
8})
9​
10test('Navigating to a post page', async ({ page }) => {
11 await page.getByRole('link', { name: 'Posts', exact: true }).click()
12 await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
13 await expect(page.getByRole('heading')).toContainText('sunt aut facere')
14})
15​
16test('Navigating nested layouts', async ({ page }) => {
17 await page.getByRole('link', { name: 'Layout', exact: true }).click()
18​
19 await expect(page.locator('#app')).toContainText("I'm a layout")
20 await expect(page.locator('#app')).toContainText("I'm a nested layout")
21​
22 await page.getByRole('link', { name: 'Layout A' }).click()
23 await expect(page.locator('#app')).toContainText("I'm layout A!")
24​
25 await page.getByRole('link', { name: 'Layout B' }).click()
26 await expect(page.locator('#app')).toContainText("I'm layout B!")
27})
28​
29test('Navigating to a not-found route', async ({ page }) => {
30 await page.getByRole('link', { name: 'This Route Does Not Exist' }).click()
31 await expect(page.getByRole('paragraph')).toContainText(
32 'This is the notFoundComponent configured on root route',
33 )
34 await page.getByRole('link', { name: 'Start Over' }).click()
35 await expect(page.getByRole('heading')).toContainText('Welcome Home!')
36})
37​
38test('Navigating to a post page with viewTransition', async ({ page }) => {
39 await page.getByRole('link', { name: 'View Transition', exact: true }).click()
40 await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
41 await expect(page.getByRole('heading')).toContainText('sunt aut facere')
42})
43​
44test('Navigating to a post page with viewTransition types', async ({
45 page,
46}) => {
47 await page.getByRole('link', { name: 'View Transition types' }).click()
48 await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
49 await expect(page.getByRole('heading')).toContainText('sunt aut facere')
50})
51​
52test('Link in SVG does not trigger a full page reload', async ({ page }) => {
53 let fullPageLoad = false
54 page.on('domcontentloaded', () => {
55 fullPageLoad = true
56 })
57​
58 await page.getByRole('link', { name: 'Open posts from SVG' }).click()
59 const url = `http://localhost:${PORT}/posts`
60 await page.waitForURL(url)
61​
62 expect(fullPageLoad).toBeFalsy()
63})