@@ -14,17 +14,20 @@ import { setIsServer } from './utils'
14
14
describe ( 'Server Side Rendering' , ( ) => {
15
15
setIsServer ( true )
16
16
17
+ let queryCache : QueryCache
18
+ let queryClient : QueryClient
19
+
17
20
beforeEach ( ( ) => {
18
21
vi . useFakeTimers ( )
22
+ queryCache = new QueryCache ( )
23
+ queryClient = new QueryClient ( { queryCache } )
19
24
} )
20
25
21
26
afterEach ( ( ) => {
22
27
vi . useRealTimers ( )
23
28
} )
24
29
25
30
it ( 'should not trigger fetch' , ( ) => {
26
- const queryCache = new QueryCache ( )
27
- const queryClient = new QueryClient ( { queryCache } )
28
31
const key = queryKey ( )
29
32
const queryFn = vi . fn ( ) . mockReturnValue ( 'data' )
30
33
@@ -52,8 +55,6 @@ describe('Server Side Rendering', () => {
52
55
} )
53
56
54
57
it ( 'should add prefetched data to cache' , async ( ) => {
55
- const queryCache = new QueryCache ( )
56
- const queryClient = new QueryClient ( { queryCache } )
57
58
const key = queryKey ( )
58
59
const fetchFn = ( ) => Promise . resolve ( 'data' )
59
60
const data = await queryClient . fetchQuery ( {
@@ -66,8 +67,6 @@ describe('Server Side Rendering', () => {
66
67
} )
67
68
68
69
it ( 'should return existing data from the cache' , async ( ) => {
69
- const queryCache = new QueryCache ( )
70
- const queryClient = new QueryClient ( { queryCache } )
71
70
const key = queryKey ( )
72
71
const queryFn = vi . fn ( async ( ) => {
73
72
await vi . advanceTimersByTimeAsync ( 10 )
@@ -102,9 +101,6 @@ describe('Server Side Rendering', () => {
102
101
it ( 'should add initialData to the cache' , ( ) => {
103
102
const key = queryKey ( )
104
103
105
- const queryCache = new QueryCache ( )
106
- const queryClient = new QueryClient ( { queryCache } )
107
-
108
104
function Page ( ) {
109
105
const [ page , setPage ] = React . useState ( 1 )
110
106
const { data } = useQuery ( {
@@ -134,8 +130,6 @@ describe('Server Side Rendering', () => {
134
130
} )
135
131
136
132
it ( 'useInfiniteQuery should return the correct state' , async ( ) => {
137
- const queryCache = new QueryCache ( )
138
- const queryClient = new QueryClient ( { queryCache } )
139
133
const key = queryKey ( )
140
134
const queryFn = vi . fn ( async ( ) => {
141
135
await vi . advanceTimersByTimeAsync ( 5 )
0 commit comments