Open History to see the last commit
1import { expect, test } from '@playwright/test'
2import { getDummyServerPort } from '@tanstack/router-e2e-utils'
3import packageJson from '../package.json' with { type: 'json' }
4β
5test.beforeEach(async ({ page }) => {
6 await page.goto('/')
7})
8β
9test('GetPosts', async () => {
10 const port = await getDummyServerPort(packageJson.name)
11 const res = await fetch(`http://localhost:${port}/posts`)
12β
13 expect(res.status).toBe(200)
14β
15 const posts = await res.json()
16β
17 expect(posts.length).toBeGreaterThan(0)
18β
19 const postRes = await fetch(`http://localhost:${port}/posts/1`)
20 expect(postRes.status).toBe(200)
21 const post = await postRes.json()
22 expect(post).toEqual(posts[0])
23})
24β
25test('Navigating to a post page', async ({ page }) => {
26 await page.getByRole('link', { name: 'Posts' }).click()
27 await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
28 await expect(page.getByRole('heading')).toContainText('sunt aut facere')
29})
30β
31test('Navigating nested layouts', async ({ page }) => {
32 await page.getByRole('link', { name: 'Layout', exact: true }).click()
33β
34 await expect(page.locator('#app')).toContainText("I'm a layout")
35 await expect(page.locator('#app')).toContainText("I'm a nested layout")
36β
37 await page.getByRole('link', { name: 'Layout A' }).click()
38 await expect(page.locator('#app')).toContainText("I'm layout A!")
39β
40 await page.getByRole('link', { name: 'Layout B' }).click()
41 await expect(page.locator('#app')).toContainText("I'm layout B!")
42})
43β
44test('Navigating to a not-found route', async ({ page }) => {
45 await page.getByRole('link', { name: 'This Route Does Not Exist' }).click()
46 await expect(page.getByRole('paragraph')).toContainText(
47 'This is the notFoundComponent configured on root route',
48 )
49 await page.getByRole('link', { name: 'Start Over' }).click()
50 await expect(page.getByRole('heading')).toContainText('Welcome Home!')
51})