@@ -14,17 +14,20 @@ import { setIsServer } from './utils'
1414describe ( 'Server Side Rendering' , ( ) => {
1515 setIsServer ( true )
1616
17+ let queryCache : QueryCache
18+ let queryClient : QueryClient
19+
1720 beforeEach ( ( ) => {
1821 vi . useFakeTimers ( )
22+ queryCache = new QueryCache ( )
23+ queryClient = new QueryClient ( { queryCache } )
1924 } )
2025
2126 afterEach ( ( ) => {
2227 vi . useRealTimers ( )
2328 } )
2429
2530 it ( 'should not trigger fetch' , ( ) => {
26- const queryCache = new QueryCache ( )
27- const queryClient = new QueryClient ( { queryCache } )
2831 const key = queryKey ( )
2932 const queryFn = vi . fn ( ) . mockReturnValue ( 'data' )
3033
@@ -52,8 +55,6 @@ describe('Server Side Rendering', () => {
5255 } )
5356
5457 it ( 'should add prefetched data to cache' , async ( ) => {
55- const queryCache = new QueryCache ( )
56- const queryClient = new QueryClient ( { queryCache } )
5758 const key = queryKey ( )
5859 const fetchFn = ( ) => Promise . resolve ( 'data' )
5960 const data = await queryClient . fetchQuery ( {
@@ -66,8 +67,6 @@ describe('Server Side Rendering', () => {
6667 } )
6768
6869 it ( 'should return existing data from the cache' , async ( ) => {
69- const queryCache = new QueryCache ( )
70- const queryClient = new QueryClient ( { queryCache } )
7170 const key = queryKey ( )
7271 const queryFn = vi . fn ( async ( ) => {
7372 await vi . advanceTimersByTimeAsync ( 10 )
@@ -102,9 +101,6 @@ describe('Server Side Rendering', () => {
102101 it ( 'should add initialData to the cache' , ( ) => {
103102 const key = queryKey ( )
104103
105- const queryCache = new QueryCache ( )
106- const queryClient = new QueryClient ( { queryCache } )
107-
108104 function Page ( ) {
109105 const [ page , setPage ] = React . useState ( 1 )
110106 const { data } = useQuery ( {
@@ -134,8 +130,6 @@ describe('Server Side Rendering', () => {
134130 } )
135131
136132 it ( 'useInfiniteQuery should return the correct state' , async ( ) => {
137- const queryCache = new QueryCache ( )
138- const queryClient = new QueryClient ( { queryCache } )
139133 const key = queryKey ( )
140134 const queryFn = vi . fn ( async ( ) => {
141135 await vi . advanceTimersByTimeAsync ( 5 )
0 commit comments