@@ -92,50 +92,48 @@ test('can prefetch using link props', async ({ page, browser }) => {
92
92
await page . getByRole ( 'link' , { name : 'On Hover + Mount' } ) . click ( )
93
93
await isPrefetchPage ( page , 4 )
94
94
expect ( requests . requests . length ) . toBe ( 0 )
95
+ } )
95
96
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 )
101
100
// 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 ( )
104
103
expect ( requests . requests . length ) . toBe ( 0 )
105
104
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 )
108
107
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 )
112
111
expect ( requests . requests . length ) . toBe ( 1 )
113
- await context2 . close ( )
114
112
115
113
// 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 ( )
118
116
119
117
// 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' )
122
120
123
- await page3 . goto ( 'prefetch/2' )
121
+ await page2 . goto ( 'prefetch/2' )
124
122
125
123
// These two prefetch requests should be made on mount
126
- await page3Prefetch2
127
- await page3Prefetch4
124
+ await prefetch2
125
+ await prefetch4
128
126
129
- requests . listen ( page3 )
127
+ requests . listen ( page2 )
130
128
131
- const link = page3 . getByRole ( 'link' , { exact : true , name : 'On Hover (Default)' } )
129
+ const link = page2 . getByRole ( 'link' , { exact : true , name : 'On Hover (Default)' } )
132
130
const box = await link . boundingBox ( )
133
131
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 )
136
134
expect ( requests . requests . length ) . toBe ( 1 )
137
- await isPrefetchPage ( page3 , 1 )
138
- await context3 . close ( )
135
+ await isPrefetchPage ( page2 , 1 )
136
+ await context2 . close ( )
139
137
} )
140
138
141
139
test ( 'can cache links with single cache value' , async ( { page } ) => {
0 commit comments