Skip to content

Commit ae80436

Browse files
committed
making it its own test case should do it for sure
1 parent 5b8a12d commit ae80436

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

tests/prefetch.spec.ts

+24-26
Original file line numberDiff line numberDiff line change
@@ -92,50 +92,48 @@ test('can prefetch using link props', async ({ page, browser }) => {
9292
await page.getByRole('link', { name: 'On Hover + Mount' }).click()
9393
await isPrefetchPage(page, 4)
9494
expect(requests.requests.length).toBe(0)
95+
})
9596

96-
// Create a new context to test the focus/blur behavior without the cache populated by previous tests
97-
const context2 = await browser.newContext()
98-
const page2 = await context2.newPage()
99-
await page2.goto('prefetch/2')
100-
requests.listen(page2)
97+
test('can prefetch link on focus', async ({ page, browser }) => {
98+
await page.goto('prefetch/2')
99+
requests.listen(page)
101100
// If they just do a quick focus, it shouldn't make the request
102-
await page2.getByRole('link', { exact: true, name: 'On Hover (Default)' }).focus()
103-
await page2.getByRole('link', { exact: true, name: 'On Hover (Default)' }).blur()
101+
await page.getByRole('link', { exact: true, name: 'On Hover (Default)' }).focus()
102+
await page.getByRole('link', { exact: true, name: 'On Hover (Default)' }).blur()
104103
expect(requests.requests.length).toBe(0)
105104

106-
await page2.getByRole('link', { exact: true, name: 'On Hover (Default)' }).focus()
107-
await page2.waitForTimeout(100)
105+
await page.getByRole('link', { exact: true, name: 'On Hover (Default)' }).focus()
106+
await page.waitForTimeout(80)
108107
expect(requests.requests.length).toBe(1)
109-
await isPrefetchPage(page2, 2)
110-
await page2.keyboard.down('Enter')
111-
await isPrefetchPage(page2, 1)
108+
await isPrefetchPage(page, 2)
109+
await page.keyboard.down('Enter')
110+
await isPrefetchPage(page, 1)
112111
expect(requests.requests.length).toBe(1)
113-
await context2.close()
114112

115113
// Create a new context to simulate touchscreen
116-
const context3 = await browser.newContext({ hasTouch: true })
117-
const page3 = await context3.newPage()
114+
const context2 = await browser.newContext({ hasTouch: true })
115+
const page2 = await context2.newPage()
118116

119117
// These two prefetch requests should be made on mount
120-
const page3Prefetch2 = page3.waitForResponse('prefetch/2')
121-
const page3Prefetch4 = page3.waitForResponse('prefetch/4')
118+
const prefetch2 = page2.waitForResponse('prefetch/2')
119+
const prefetch4 = page2.waitForResponse('prefetch/4')
122120

123-
await page3.goto('prefetch/2')
121+
await page2.goto('prefetch/2')
124122

125123
// These two prefetch requests should be made on mount
126-
await page3Prefetch2
127-
await page3Prefetch4
124+
await prefetch2
125+
await prefetch4
128126

129-
requests.listen(page3)
127+
requests.listen(page2)
130128

131-
const link = page3.getByRole('link', { exact: true, name: 'On Hover (Default)' })
129+
const link = page2.getByRole('link', { exact: true, name: 'On Hover (Default)' })
132130
const box = await link.boundingBox()
133131
expect(box).not.toBeNull()
134-
page3.touchscreen.tap(box!.x, box!.y)
135-
await page3.waitForTimeout(75)
132+
page2.touchscreen.tap(box!.x, box!.y)
133+
await page2.waitForTimeout(75)
136134
expect(requests.requests.length).toBe(1)
137-
await isPrefetchPage(page3, 1)
138-
await context3.close()
135+
await isPrefetchPage(page2, 1)
136+
await context2.close()
139137
})
140138

141139
test('can cache links with single cache value', async ({ page }) => {

0 commit comments

Comments
 (0)