@@ -37,16 +37,14 @@ describe('app dir - prefetching (custom staleTime)', () => {
3737 async ( ) => {
3838 const reveal = await browser . elementByCss ( '#accordion-to-static-page' )
3939 await reveal . click ( )
40- await browser . waitForElementByCss ( '#to-static-page' )
41- return await browser . elementByCss ( '#to-static-page' )
40+ return browser . elementByCss ( '#to-static-page' )
4241 } ,
4342 { includes : 'Static Page [prefetch-sentinel]' }
4443 )
4544
4645 // Navigate to static page - should use prefetched data with no additional requests
4746 await act ( async ( ) => {
4847 await link . click ( )
49- await browser . waitForElementByCss ( '#static-page' )
5048 const staticPageText = await browser . elementByCss ( '#static-page' ) . text ( )
5149 expect ( staticPageText ) . toBe ( 'Static Page [prefetch-sentinel]' )
5250 } , 'no-requests' )
@@ -66,12 +64,12 @@ describe('app dir - prefetching (custom staleTime)', () => {
6664 await browser . waitForElementByCss ( '#to-static-page' )
6765
6866 // Navigate to static page again using the accordion - should still use cached data with no additional requests
69- await act ( async ( ) => {
67+ const staticPageText = await act ( async ( ) => {
7068 await browser . elementByCss ( '#to-static-page' ) . click ( )
71- await browser . waitForElementByCss ( '#static-page' )
72- const staticPageText = await browser . elementByCss ( '#static-page' ) . text ( )
73- expect ( staticPageText ) . toBe ( 'Static Page [prefetch-sentinel]' )
69+ return browser . elementByCss ( '#static-page' ) . text ( )
7470 } , 'no-requests' )
71+
72+ expect ( staticPageText ) . toBe ( 'Static Page [prefetch-sentinel]' )
7573 } )
7674
7775 it ( 'should fetch again when a static page was prefetched when navigating to it after the stale time has passed' , async ( ) => {
@@ -91,8 +89,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
9189 async ( ) => {
9290 const reveal = await browser . elementByCss ( '#accordion-to-static-page' )
9391 await reveal . click ( )
94- await browser . waitForElementByCss ( '#to-static-page' )
95- return await browser . elementByCss ( '#to-static-page' )
92+ return browser . elementByCss ( '#to-static-page' )
9693 } ,
9794 { includes : 'Static Page [prefetch-sentinel]' }
9895 )
@@ -118,8 +115,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
118115 async ( ) => {
119116 const reveal = await browser . elementByCss ( '#accordion-to-static-page' )
120117 await reveal . click ( )
121- await browser . waitForElementByCss ( '#to-static-page' )
122- return await browser . elementByCss ( '#to-static-page' )
118+ return browser . elementByCss ( '#to-static-page' )
123119 } ,
124120 { includes : 'Static Page [prefetch-sentinel]' }
125121 )
@@ -153,9 +149,10 @@ describe('app dir - prefetching (custom staleTime)', () => {
153149 await act ( async ( ) => {
154150 await browser . elementByCss ( "[href='/prefetch-auto-route-groups']" ) . click ( )
155151 // Confirm that the dashboard page is still rendering the stale fetch count, as it should be cached
156- expect ( await browser . elementById ( 'count' ) . text ( ) ) . toBe ( '1' )
157152 } , 'no-requests' )
158153
154+ expect ( await browser . elementById ( 'count' ) . text ( ) ) . toBe ( '1' )
155+
159156 // Navigate to a new sub-page - this will trigger another data fetch
160157 await act ( async ( ) => {
161158 await browser
@@ -166,12 +163,14 @@ describe('app dir - prefetching (custom staleTime)', () => {
166163 // Finally, go back to the route group page - should use cached data with no additional fetch
167164 await act ( async ( ) => {
168165 await browser . elementByCss ( "[href='/prefetch-auto-route-groups']" ) . click ( )
169- // Confirm that the dashboard page is still rendering the stale fetch count, as it should be cached
170- expect ( await browser . elementById ( 'count' ) . text ( ) ) . toBe ( '1' )
171166 } , 'no-requests' )
172167
168+ // Confirm that the dashboard page is still rendering the stale fetch count, as it should be cached
169+ expect ( await browser . elementById ( 'count' ) . text ( ) ) . toBe ( '1' )
170+
173171 // Reload the page to get the accurate total number of fetches
174172 await browser . refresh ( )
173+
175174 // The initial fetch, 2 sub-page fetches, and a final fetch when reloading the page
176175 expect ( await browser . elementById ( 'count' ) . text ( ) ) . toBe ( '4' )
177176 } )
@@ -196,8 +195,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
196195 async ( ) => {
197196 const reveal = await browser . elementByCss ( '#accordion-to-home' )
198197 await reveal . click ( )
199- await browser . waitForElementByCss ( '#to-home' )
200- return await browser . elementByCss ( '#to-home' )
198+ return browser . elementByCss ( '#to-home' )
201199 } ,
202200 { includes : 'Home Page [prefetch-sentinel]' }
203201 )
@@ -216,21 +214,17 @@ describe('app dir - prefetching (custom staleTime)', () => {
216214 '#accordion-to-static-page-no-prefetch'
217215 )
218216 await reveal . click ( )
219- await browser . waitForElementByCss ( '#to-static-page-no-prefetch' )
220- return await browser . elementByCss ( '#to-static-page-no-prefetch' )
217+ return browser . elementByCss ( '#to-static-page-no-prefetch' )
221218 } ,
222219 { includes : 'Static Page No Prefetch [prefetch-sentinel]' }
223220 )
224221
225222 // Navigate back to static-page-no-prefetch - should use the fresh prefetch data
226- await act ( async ( ) => {
223+ const staticPageText = await act ( async ( ) => {
227224 await link . click ( )
228- await browser . waitForElementByCss ( '#static-page-no-prefetch' )
229- const staticPageText = await browser
230- . elementByCss ( '#static-page-no-prefetch' )
231- . text ( )
232- expect ( staticPageText ) . toBe ( 'Static Page No Prefetch [prefetch-sentinel]' )
225+ return browser . elementByCss ( '#static-page-no-prefetch' ) . text ( )
233226 } , 'no-requests' )
227+ expect ( staticPageText ) . toBe ( 'Static Page No Prefetch [prefetch-sentinel]' )
234228 } )
235229
236230 it ( 'should renew the stale time after refetching expired RSC data' , async ( ) => {
@@ -250,8 +244,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
250244 async ( ) => {
251245 const reveal = await browser . elementByCss ( '#accordion-to-static-page' )
252246 await reveal . click ( )
253- await browser . waitForElementByCss ( '#to-static-page' )
254- return await browser . elementByCss ( '#to-static-page' )
247+ return browser . elementByCss ( '#to-static-page' )
255248 } ,
256249 { includes : 'Static Page [prefetch-sentinel]' }
257250 )
@@ -280,8 +273,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
280273 async ( ) => {
281274 const reveal = await browser . elementByCss ( '#accordion-to-static-page' )
282275 await reveal . click ( )
283- await browser . waitForElementByCss ( '#to-static-page' )
284- return await browser . elementByCss ( '#to-static-page' )
276+ return browser . elementByCss ( '#to-static-page' )
285277 } ,
286278 { includes : 'Static Page [prefetch-sentinel]' }
287279 )
@@ -307,17 +299,15 @@ describe('app dir - prefetching (custom staleTime)', () => {
307299 link = await act ( async ( ) => {
308300 const reveal = await browser . elementByCss ( '#accordion-to-static-page' )
309301 await reveal . click ( )
310- await browser . waitForElementByCss ( '#to-static-page' )
311- return await browser . elementByCss ( '#to-static-page' )
302+ return browser . elementByCss ( '#to-static-page' )
312303 } , 'no-requests' )
313304
314305 // Navigate to static page again (should NOT refetch - stale time should be renewed)
315306 // If this assertion passes, it means the stale time was properly renewed after the refetch
316- await act ( async ( ) => {
307+ const staticPageText = await act ( async ( ) => {
317308 await link . click ( )
318- await browser . waitForElementByCss ( '#static-page' )
319- const staticPageText = await browser . elementByCss ( '#static-page' ) . text ( )
320- expect ( staticPageText ) . toBe ( 'Static Page [prefetch-sentinel]' )
309+ return browser . elementByCss ( '#static-page' ) . text ( )
321310 } , 'no-requests' )
311+ expect ( staticPageText ) . toBe ( 'Static Page [prefetch-sentinel]' )
322312 } )
323313} )
0 commit comments