Skip to content

Commit b0ec93e

Browse files
committed
Add e2e test for react-router Link in SVG
1 parent 4fdb9d0 commit b0ec93e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

e2e/react-router/basic/src/main.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,23 @@ function RootComponent() {
6969
}}
7070
>
7171
This Route Does Not Exist
72-
</Link>
72+
</Link>{' '}
73+
<div className="flex items-center">
74+
<svg width="20" height="20" viewBox="0 0 20 20" role="img">
75+
<title id="rectTitle">Link in SVG</title>
76+
<Link to="/posts" aria-label="Open posts from SVG">
77+
<rect
78+
x="0"
79+
y="0"
80+
width="20"
81+
height="20"
82+
rx="4"
83+
fill="blue"
84+
strokeWidth="2"
85+
/>
86+
</Link>
87+
</svg>
88+
</div>
7389
</div>
7490
<Outlet />
7591
<TanStackRouterDevtools position="bottom-right" />

e2e/react-router/basic/tests/app.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { expect, test } from '@playwright/test'
2+
import { getTestServerPort } from '@tanstack/router-e2e-utils'
3+
import packageJson from '../package.json' with { type: 'json' }
4+
5+
const PORT = await getTestServerPort(packageJson.name)
26

37
test.beforeEach(async ({ page }) => {
48
await page.goto('/')
@@ -45,3 +49,16 @@ test('Navigating to a post page with viewTransition types', async ({
4549
await page.getByRole('link', { name: 'sunt aut facere repe' }).click()
4650
await expect(page.getByRole('heading')).toContainText('sunt aut facere')
4751
})
52+
53+
test('Link in SVG does not trigger a full page reload', async ({ page }) => {
54+
let fullPageLoad = false
55+
page.on('domcontentloaded', () => {
56+
fullPageLoad = true
57+
})
58+
59+
await page.getByRole('link', { name: 'Open posts from SVG' }).click()
60+
const url = `http://localhost:${PORT}/posts`
61+
await page.waitForURL(url)
62+
63+
expect(fullPageLoad).toBeFalsy()
64+
})

0 commit comments

Comments
 (0)