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

hover-preload-hash.spec.ts

25 lines978 Bytes

1import { expect } from '@playwright/test'
2import { apiTest as test } from '@tanstack/router-e2e-utils'
3import { toRuntimePath } from '@tanstack/router-e2e-utils'
4​
5test('clicking hash link then hovering another link does not scroll back to hash', async ({
6 page,
7}) => {
8 // Go to the page without hash
9 await page.goto(toRuntimePath('/hover-preload-hash'))
10​
11 // Click the hash link to navigate to position1
12 await page.getByTestId('link-to-hash').click()
13 await expect(page.locator('#position1')).toBeInViewport()
14​
15 // Scroll up so position1 is no longer in view
16 await page.evaluate(() => window.scrollTo(0, 0))
17 await expect(page.locator('#position1')).not.toBeInViewport()
18​
19 // Hover the link to trigger intent preload (should NOT scroll back)
20 await page.getByTestId('link-to-only-route-inside-group').hover()
21 await page.waitForTimeout(400)
22​
23 // Ensure we did not jump back to the hash target
24 await expect(page.locator('#position1')).not.toBeInViewport()
25})