@tanstack/query-core 4.24.10 → 5.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/focusManager.d.ts +1 -3
- package/build/lib/focusManager.esm.js +19 -36
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +19 -38
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.mjs +19 -36
- package/build/lib/focusManager.mjs.map +1 -1
- package/build/lib/hydration.esm.js +21 -23
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +21 -25
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +21 -23
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +1 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +2 -8
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/infiniteQueryBehavior.d.ts +3 -7
- package/build/lib/infiniteQueryBehavior.esm.js +52 -75
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +50 -77
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.mjs +52 -75
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +4 -4
- package/build/lib/infiniteQueryObserver.esm.js +18 -26
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +18 -28
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs +18 -26
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +11 -22
- package/build/lib/mutation.esm.js +73 -105
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +73 -107
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +73 -105
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +4 -6
- package/build/lib/mutationCache.esm.js +23 -32
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +23 -34
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +23 -32
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.d.ts +4 -9
- package/build/lib/mutationObserver.esm.js +42 -73
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +42 -75
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +42 -73
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/notifyManager.esm.js +7 -17
- package/build/lib/notifyManager.esm.js.map +1 -1
- package/build/lib/notifyManager.js +7 -19
- package/build/lib/notifyManager.js.map +1 -1
- package/build/lib/notifyManager.mjs +7 -17
- package/build/lib/notifyManager.mjs.map +1 -1
- package/build/lib/onlineManager.d.ts +1 -3
- package/build/lib/onlineManager.esm.js +16 -30
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +16 -32
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.mjs +16 -30
- package/build/lib/onlineManager.mjs.map +1 -1
- package/build/lib/queriesObserver.d.ts +3 -10
- package/build/lib/queriesObserver.esm.js +47 -71
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +49 -75
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +47 -71
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.d.ts +14 -21
- package/build/lib/query.esm.js +140 -194
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +139 -195
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +140 -194
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +12 -7
- package/build/lib/queryCache.esm.js +21 -45
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js +20 -46
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs +21 -45
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +18 -46
- package/build/lib/queryClient.esm.js +137 -216
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +136 -217
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +137 -216
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +4 -29
- package/build/lib/queryObserver.esm.js +176 -258
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +176 -260
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +176 -258
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/removable.d.ts +3 -3
- package/build/lib/removable.esm.js +10 -14
- package/build/lib/removable.esm.js.map +1 -1
- package/build/lib/removable.js +10 -16
- package/build/lib/removable.js.map +1 -1
- package/build/lib/removable.mjs +10 -14
- package/build/lib/removable.mjs.map +1 -1
- package/build/lib/retryer.d.ts +5 -5
- package/build/lib/retryer.esm.js +27 -44
- package/build/lib/retryer.esm.js.map +1 -1
- package/build/lib/retryer.js +27 -46
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/retryer.mjs +27 -44
- package/build/lib/retryer.mjs.map +1 -1
- package/build/lib/subscribable.esm.js +4 -7
- package/build/lib/subscribable.esm.js.map +1 -1
- package/build/lib/subscribable.js +4 -9
- package/build/lib/subscribable.js.map +1 -1
- package/build/lib/subscribable.mjs +4 -7
- package/build/lib/subscribable.mjs.map +1 -1
- package/build/lib/tests/utils.d.ts +3 -12
- package/build/lib/types.d.ts +111 -99
- package/build/lib/utils.d.ts +8 -18
- package/build/lib/utils.esm.js +39 -132
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +42 -144
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +39 -132
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +867 -1399
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/focusManager.ts +17 -24
- package/src/index.ts +1 -11
- package/src/infiniteQueryBehavior.ts +54 -94
- package/src/infiniteQueryObserver.ts +10 -12
- package/src/mutation.ts +68 -92
- package/src/mutationCache.ts +27 -27
- package/src/mutationObserver.ts +58 -97
- package/src/onlineManager.ts +14 -14
- package/src/queriesObserver.ts +50 -54
- package/src/query.ts +107 -111
- package/src/queryCache.ts +42 -41
- package/src/queryClient.ts +155 -434
- package/src/queryObserver.ts +155 -192
- package/src/removable.ts +13 -13
- package/src/retryer.ts +5 -5
- package/src/subscribable.ts +1 -1
- package/src/tests/focusManager.test.tsx +25 -25
- package/src/tests/hydration.test.tsx +167 -81
- package/src/tests/infiniteQueryBehavior.test.tsx +209 -17
- package/src/tests/infiniteQueryObserver.test.tsx +6 -2
- package/src/tests/mutationCache.test.tsx +127 -127
- package/src/tests/mutationObserver.test.tsx +1 -31
- package/src/tests/mutations.test.tsx +62 -43
- package/src/tests/onlineManager.test.tsx +12 -4
- package/src/tests/queriesObserver.test.tsx +41 -77
- package/src/tests/query.test.tsx +175 -243
- package/src/tests/queryCache.test.tsx +170 -93
- package/src/tests/queryClient.test.tsx +229 -378
- package/src/tests/queryObserver.test.tsx +23 -147
- package/src/tests/utils.test.tsx +84 -29
- package/src/tests/utils.ts +9 -18
- package/src/types.ts +187 -140
- package/src/utils.ts +31 -124
- package/build/lib/logger.d.ts +0 -8
- package/build/lib/logger.esm.js +0 -4
- package/build/lib/logger.esm.js.map +0 -1
- package/build/lib/logger.js +0 -8
- package/build/lib/logger.js.map +0 -1
- package/build/lib/logger.mjs +0 -4
- package/build/lib/logger.mjs.map +0 -1
- package/build/lib/logger.native.d.ts +0 -6
- package/build/lib/logger.native.esm.js +0 -12
- package/build/lib/logger.native.esm.js.map +0 -1
- package/build/lib/logger.native.js +0 -16
- package/build/lib/logger.native.js.map +0 -1
- package/build/lib/logger.native.mjs +0 -12
- package/build/lib/logger.native.mjs.map +0 -1
- package/src/logger.native.ts +0 -11
- package/src/logger.ts +0 -9
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { waitFor } from '@testing-library/react'
|
|
2
2
|
import '@testing-library/jest-dom'
|
|
3
3
|
|
|
4
|
-
import { sleep, queryKey,
|
|
4
|
+
import { sleep, queryKey, createQueryClient } from './utils'
|
|
5
5
|
import type {
|
|
6
6
|
QueryCache,
|
|
7
7
|
QueryClient,
|
|
8
8
|
QueryFunction,
|
|
9
9
|
QueryObserverOptions,
|
|
10
10
|
} from '..'
|
|
11
|
-
import {
|
|
11
|
+
import { MutationObserver, QueryObserver } from '..'
|
|
12
12
|
import { focusManager, onlineManager } from '..'
|
|
13
13
|
import { noop } from '../utils'
|
|
14
14
|
|
|
@@ -36,7 +36,7 @@ describe('queryClient', () => {
|
|
|
36
36
|
defaultOptions: { queries: { queryFn } },
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
expect(() => testClient.prefetchQuery(key)).not.toThrow()
|
|
39
|
+
expect(() => testClient.prefetchQuery({ queryKey: key })).not.toThrow()
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
test('should merge defaultOptions when query is added to cache', async () => {
|
|
@@ -44,14 +44,14 @@ describe('queryClient', () => {
|
|
|
44
44
|
|
|
45
45
|
const testClient = createQueryClient({
|
|
46
46
|
defaultOptions: {
|
|
47
|
-
queries: {
|
|
47
|
+
queries: { gcTime: Infinity },
|
|
48
48
|
},
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
const fetchData = () => Promise.resolve('data')
|
|
52
|
-
await testClient.prefetchQuery(key, fetchData)
|
|
53
|
-
const newQuery = testClient.getQueryCache().find(key)
|
|
54
|
-
expect(newQuery?.options.
|
|
52
|
+
await testClient.prefetchQuery({ queryKey: key, queryFn: fetchData })
|
|
53
|
+
const newQuery = testClient.getQueryCache().find({ queryKey: key })
|
|
54
|
+
expect(newQuery?.options.gcTime).toBe(Infinity)
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
test('should get defaultOptions', async () => {
|
|
@@ -93,7 +93,9 @@ describe('queryClient', () => {
|
|
|
93
93
|
|
|
94
94
|
test('should not match if the query key is a subset', async () => {
|
|
95
95
|
const key = queryKey()
|
|
96
|
-
queryClient.setQueryDefaults([key, 'a'], {
|
|
96
|
+
queryClient.setQueryDefaults([key, 'a'], {
|
|
97
|
+
queryFn: () => 'data',
|
|
98
|
+
})
|
|
97
99
|
const observer = new QueryObserver(queryClient, {
|
|
98
100
|
queryKey: [key],
|
|
99
101
|
retry: false,
|
|
@@ -112,7 +114,7 @@ describe('queryClient', () => {
|
|
|
112
114
|
const observer = new QueryObserver(queryClient, {
|
|
113
115
|
queryKey: [key],
|
|
114
116
|
})
|
|
115
|
-
expect(observer.getCurrentResult().status).toBe('
|
|
117
|
+
expect(observer.getCurrentResult().status).toBe('pending')
|
|
116
118
|
expect(observer.getCurrentResult().fetchStatus).toBe('idle')
|
|
117
119
|
})
|
|
118
120
|
|
|
@@ -120,128 +122,22 @@ describe('queryClient', () => {
|
|
|
120
122
|
const key = queryKey()
|
|
121
123
|
const queryOptions1 = { queryFn: () => 'data' }
|
|
122
124
|
const queryOptions2 = { retry: false }
|
|
123
|
-
queryClient.setQueryDefaults(key, queryOptions1)
|
|
124
|
-
queryClient.setQueryDefaults(key, queryOptions2)
|
|
125
|
+
queryClient.setQueryDefaults(key, { ...queryOptions1 })
|
|
126
|
+
queryClient.setQueryDefaults(key, { ...queryOptions2 })
|
|
125
127
|
expect(queryClient.getQueryDefaults(key)).toMatchObject(queryOptions2)
|
|
126
128
|
})
|
|
127
129
|
|
|
128
|
-
test('should
|
|
129
|
-
|
|
130
|
-
const keyABCD = [
|
|
131
|
-
{
|
|
132
|
-
a: 'a',
|
|
133
|
-
b: 'b',
|
|
134
|
-
c: 'c',
|
|
135
|
-
d: 'd',
|
|
136
|
-
},
|
|
137
|
-
]
|
|
138
|
-
|
|
139
|
-
// The key below "contains" keyABCD => it is more generic
|
|
140
|
-
const keyABC = [
|
|
141
|
-
{
|
|
142
|
-
a: 'a',
|
|
143
|
-
b: 'b',
|
|
144
|
-
c: 'c',
|
|
145
|
-
},
|
|
146
|
-
]
|
|
147
|
-
|
|
148
|
-
// The defaults for query matching key "ABCD" (least generic)
|
|
149
|
-
const defaultsOfABCD = {
|
|
150
|
-
queryFn: function ABCDQueryFn() {
|
|
151
|
-
return 'ABCD'
|
|
152
|
-
},
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// The defaults for query matching key "ABC" (most generic)
|
|
156
|
-
const defaultsOfABC = {
|
|
157
|
-
queryFn: function ABCQueryFn() {
|
|
158
|
-
return 'ABC'
|
|
159
|
-
},
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// No defaults, no warning
|
|
163
|
-
const noDefaults = queryClient.getQueryDefaults(keyABCD)
|
|
164
|
-
expect(noDefaults).toBeUndefined()
|
|
165
|
-
expect(mockLogger.error).toHaveBeenCalledTimes(1)
|
|
166
|
-
|
|
167
|
-
// If defaults for key ABCD are registered **before** the ones of key ABC (more generic)…
|
|
168
|
-
queryClient.setQueryDefaults(keyABCD, defaultsOfABCD)
|
|
169
|
-
queryClient.setQueryDefaults(keyABC, defaultsOfABC)
|
|
170
|
-
// … then the "good" defaults are retrieved: we get the ones for key "ABCD"
|
|
171
|
-
const goodDefaults = queryClient.getQueryDefaults(keyABCD)
|
|
172
|
-
expect(goodDefaults).toBe(defaultsOfABCD)
|
|
173
|
-
// The warning is still raised since several defaults are matching
|
|
174
|
-
expect(mockLogger.error).toHaveBeenCalledTimes(2)
|
|
175
|
-
|
|
176
|
-
// Let's create another queryClient and change the order of registration
|
|
177
|
-
const newQueryClient = createQueryClient()
|
|
178
|
-
// The defaults for key ABC (more generic) are registered **before** the ones of key ABCD…
|
|
179
|
-
newQueryClient.setQueryDefaults(keyABC, defaultsOfABC)
|
|
180
|
-
newQueryClient.setQueryDefaults(keyABCD, defaultsOfABCD)
|
|
181
|
-
// … then the "wrong" defaults are retrieved: we get the ones for key "ABC"
|
|
182
|
-
const badDefaults = newQueryClient.getQueryDefaults(keyABCD)
|
|
183
|
-
expect(badDefaults).not.toBe(defaultsOfABCD)
|
|
184
|
-
expect(badDefaults).toBe(defaultsOfABC)
|
|
185
|
-
expect(mockLogger.error).toHaveBeenCalledTimes(4)
|
|
186
|
-
})
|
|
187
|
-
|
|
188
|
-
test('should warn in dev if several mutation defaults match a given key', () => {
|
|
189
|
-
// Check discussion here: https://github.com/tannerlinsley/react-query/discussions/3199
|
|
190
|
-
const keyABCD = [
|
|
191
|
-
{
|
|
192
|
-
a: 'a',
|
|
193
|
-
b: 'b',
|
|
194
|
-
c: 'c',
|
|
195
|
-
d: 'd',
|
|
196
|
-
},
|
|
197
|
-
]
|
|
198
|
-
|
|
199
|
-
// The key below "contains" keyABCD => it is more generic
|
|
200
|
-
const keyABC = [
|
|
201
|
-
{
|
|
202
|
-
a: 'a',
|
|
203
|
-
b: 'b',
|
|
204
|
-
c: 'c',
|
|
205
|
-
},
|
|
206
|
-
]
|
|
207
|
-
|
|
208
|
-
// The defaults for mutation matching key "ABCD" (least generic)
|
|
209
|
-
const defaultsOfABCD = {
|
|
210
|
-
mutationFn: Promise.resolve,
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// The defaults for mutation matching key "ABC" (most generic)
|
|
214
|
-
const defaultsOfABC = {
|
|
215
|
-
mutationFn: Promise.resolve,
|
|
216
|
-
}
|
|
130
|
+
test('should merge defaultOptions', async () => {
|
|
131
|
+
const key = queryKey()
|
|
217
132
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
1,
|
|
223
|
-
'Passing a custom logger has been deprecated and will be removed in the next major version.',
|
|
224
|
-
)
|
|
133
|
+
queryClient.setQueryDefaults([...key, 'todo'], { suspense: true })
|
|
134
|
+
queryClient.setQueryDefaults([...key, 'todo', 'detail'], {
|
|
135
|
+
staleTime: 5000,
|
|
136
|
+
})
|
|
225
137
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// … then the "good" defaults are retrieved: we get the ones for key "ABCD"
|
|
230
|
-
const goodDefaults = queryClient.getMutationDefaults(keyABCD)
|
|
231
|
-
expect(goodDefaults).toBe(defaultsOfABCD)
|
|
232
|
-
// The warning is still raised since several defaults are matching
|
|
233
|
-
expect(mockLogger.error).toHaveBeenCalledTimes(2)
|
|
234
|
-
|
|
235
|
-
// Let's create another queryClient and change the order of registration
|
|
236
|
-
const newQueryClient = createQueryClient()
|
|
237
|
-
// The defaults for key ABC (more generic) are registered **before** the ones of key ABCD…
|
|
238
|
-
newQueryClient.setMutationDefaults(keyABC, defaultsOfABC)
|
|
239
|
-
newQueryClient.setMutationDefaults(keyABCD, defaultsOfABCD)
|
|
240
|
-
// … then the "wrong" defaults are retrieved: we get the ones for key "ABC"
|
|
241
|
-
const badDefaults = newQueryClient.getMutationDefaults(keyABCD)
|
|
242
|
-
expect(badDefaults).not.toBe(defaultsOfABCD)
|
|
243
|
-
expect(badDefaults).toBe(defaultsOfABC)
|
|
244
|
-
expect(mockLogger.error).toHaveBeenCalledTimes(4)
|
|
138
|
+
expect(
|
|
139
|
+
queryClient.getQueryDefaults([...key, 'todo', 'detail']),
|
|
140
|
+
).toMatchObject({ suspense: true, staleTime: 5000 })
|
|
245
141
|
})
|
|
246
142
|
})
|
|
247
143
|
|
|
@@ -273,7 +169,7 @@ describe('queryClient', () => {
|
|
|
273
169
|
const testCache = testClient.getQueryCache()
|
|
274
170
|
testClient.setQueryData(key, 'data')
|
|
275
171
|
expect(testClient.getQueryData(key)).toBe('data')
|
|
276
|
-
expect(testCache.find(key)).toBe(testCache.get('someKey'))
|
|
172
|
+
expect(testCache.find({ queryKey: key })).toBe(testCache.get('someKey'))
|
|
277
173
|
})
|
|
278
174
|
|
|
279
175
|
test('should create a new query if query was not found', () => {
|
|
@@ -290,16 +186,24 @@ describe('queryClient', () => {
|
|
|
290
186
|
|
|
291
187
|
test('should not create a new query if query was not found and data is undefined', () => {
|
|
292
188
|
const key = queryKey()
|
|
293
|
-
expect(queryClient.getQueryCache().find(key)).toBe(
|
|
189
|
+
expect(queryClient.getQueryCache().find({ queryKey: key })).toBe(
|
|
190
|
+
undefined,
|
|
191
|
+
)
|
|
294
192
|
queryClient.setQueryData(key, undefined)
|
|
295
|
-
expect(queryClient.getQueryCache().find(key)).toBe(
|
|
193
|
+
expect(queryClient.getQueryCache().find({ queryKey: key })).toBe(
|
|
194
|
+
undefined,
|
|
195
|
+
)
|
|
296
196
|
})
|
|
297
197
|
|
|
298
198
|
test('should not create a new query if query was not found and updater returns undefined', () => {
|
|
299
199
|
const key = queryKey()
|
|
300
|
-
expect(queryClient.getQueryCache().find(key)).toBe(
|
|
200
|
+
expect(queryClient.getQueryCache().find({ queryKey: key })).toBe(
|
|
201
|
+
undefined,
|
|
202
|
+
)
|
|
301
203
|
queryClient.setQueryData(key, () => undefined)
|
|
302
|
-
expect(queryClient.getQueryCache().find(key)).toBe(
|
|
204
|
+
expect(queryClient.getQueryCache().find({ queryKey: key })).toBe(
|
|
205
|
+
undefined,
|
|
206
|
+
)
|
|
303
207
|
})
|
|
304
208
|
|
|
305
209
|
test('should not update query data if data is undefined', () => {
|
|
@@ -325,19 +229,9 @@ describe('queryClient', () => {
|
|
|
325
229
|
queryClient.setQueryData(key, updater)
|
|
326
230
|
|
|
327
231
|
expect(updater).toHaveBeenCalled()
|
|
328
|
-
expect(queryCache.find(key)!.state.data).toEqual(
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
test('should use prev data if an isDataEqual function is defined and returns "true"', () => {
|
|
332
|
-
const key = queryKey()
|
|
333
|
-
|
|
334
|
-
queryClient.setDefaultOptions({
|
|
335
|
-
queries: { isDataEqual: (_prev, data) => data === 'data' },
|
|
336
|
-
})
|
|
337
|
-
queryClient.setQueryData(key, 'prev data')
|
|
338
|
-
queryClient.setQueryData(key, 'data')
|
|
339
|
-
|
|
340
|
-
expect(queryCache.find(key)!.state.data).toEqual('prev data')
|
|
232
|
+
expect(queryCache.find({ queryKey: key })!.state.data).toEqual(
|
|
233
|
+
'new data + test data',
|
|
234
|
+
)
|
|
341
235
|
})
|
|
342
236
|
|
|
343
237
|
test('should set the new data without comparison if structuralSharing is set to false', () => {
|
|
@@ -354,7 +248,7 @@ describe('queryClient', () => {
|
|
|
354
248
|
queryClient.setQueryData(key, oldData)
|
|
355
249
|
queryClient.setQueryData(key, newData)
|
|
356
250
|
|
|
357
|
-
expect(queryCache.find(key)!.state.data).toBe(newData)
|
|
251
|
+
expect(queryCache.find({ queryKey: key })!.state.data).toBe(newData)
|
|
358
252
|
})
|
|
359
253
|
|
|
360
254
|
test('should apply a custom structuralSharing function when provided', () => {
|
|
@@ -381,19 +275,22 @@ describe('queryClient', () => {
|
|
|
381
275
|
queryClient.setQueryData(key, oldData)
|
|
382
276
|
queryClient.setQueryData(key, newData)
|
|
383
277
|
|
|
384
|
-
expect(queryCache.find(key)!.state.data).toBe(oldData)
|
|
278
|
+
expect(queryCache.find({ queryKey: key })!.state.data).toBe(oldData)
|
|
385
279
|
|
|
386
280
|
const distinctData = { value: new Date(2021, 11, 25) }
|
|
387
281
|
queryClient.setQueryData(key, distinctData)
|
|
388
282
|
|
|
389
|
-
expect(queryCache.find(key)!.state.data).toBe(distinctData)
|
|
283
|
+
expect(queryCache.find({ queryKey: key })!.state.data).toBe(distinctData)
|
|
390
284
|
})
|
|
391
285
|
|
|
392
286
|
test('should not set isFetching to false', async () => {
|
|
393
287
|
const key = queryKey()
|
|
394
|
-
queryClient.prefetchQuery(
|
|
395
|
-
|
|
396
|
-
|
|
288
|
+
queryClient.prefetchQuery({
|
|
289
|
+
queryKey: key,
|
|
290
|
+
queryFn: async () => {
|
|
291
|
+
await sleep(10)
|
|
292
|
+
return 23
|
|
293
|
+
},
|
|
397
294
|
})
|
|
398
295
|
expect(queryClient.getQueryState(key)).toMatchObject({
|
|
399
296
|
data: undefined,
|
|
@@ -418,8 +315,9 @@ describe('queryClient', () => {
|
|
|
418
315
|
queryClient.setQueryData(['key', 1], 1)
|
|
419
316
|
queryClient.setQueryData(['key', 2], 2)
|
|
420
317
|
|
|
421
|
-
const result = queryClient.setQueriesData<number>(
|
|
422
|
-
|
|
318
|
+
const result = queryClient.setQueriesData<number>(
|
|
319
|
+
{ queryKey: ['key'] },
|
|
320
|
+
(old) => (old ? old + 5 : undefined),
|
|
423
321
|
)
|
|
424
322
|
|
|
425
323
|
expect(result).toEqual([
|
|
@@ -433,7 +331,7 @@ describe('queryClient', () => {
|
|
|
433
331
|
test('should accept queryFilters', () => {
|
|
434
332
|
queryClient.setQueryData(['key', 1], 1)
|
|
435
333
|
queryClient.setQueryData(['key', 2], 2)
|
|
436
|
-
const query1 = queryCache.find(['key', 1])!
|
|
334
|
+
const query1 = queryCache.find({ queryKey: ['key', 1] })!
|
|
437
335
|
|
|
438
336
|
const result = queryClient.setQueriesData<number>(
|
|
439
337
|
{ predicate: (query) => query === query1 },
|
|
@@ -446,7 +344,10 @@ describe('queryClient', () => {
|
|
|
446
344
|
})
|
|
447
345
|
|
|
448
346
|
test('should not update non existing queries', () => {
|
|
449
|
-
const result = queryClient.setQueriesData<string>(
|
|
347
|
+
const result = queryClient.setQueriesData<string>(
|
|
348
|
+
{ queryKey: ['key'] },
|
|
349
|
+
'data',
|
|
350
|
+
)
|
|
450
351
|
|
|
451
352
|
expect(result).toEqual([])
|
|
452
353
|
expect(queryClient.getQueryData(['key'])).toBe(undefined)
|
|
@@ -501,7 +402,7 @@ describe('queryClient', () => {
|
|
|
501
402
|
queryClient.setQueryData([key1, 1], 1)
|
|
502
403
|
queryClient.setQueryData([key1, 2], 2)
|
|
503
404
|
queryClient.setQueryData([key2, 2], 2)
|
|
504
|
-
expect(queryClient.getQueriesData([key1])).toEqual([
|
|
405
|
+
expect(queryClient.getQueriesData({ queryKey: [key1] })).toEqual([
|
|
505
406
|
[[key1, 1], 1],
|
|
506
407
|
[[key1, 2], 2],
|
|
507
408
|
])
|
|
@@ -509,13 +410,13 @@ describe('queryClient', () => {
|
|
|
509
410
|
|
|
510
411
|
test('should return empty array if queries are not found', () => {
|
|
511
412
|
const key = queryKey()
|
|
512
|
-
expect(queryClient.getQueriesData(key)).toEqual([])
|
|
413
|
+
expect(queryClient.getQueriesData({ queryKey: key })).toEqual([])
|
|
513
414
|
})
|
|
514
415
|
|
|
515
416
|
test('should accept query filters', () => {
|
|
516
417
|
queryClient.setQueryData(['key', 1], 1)
|
|
517
418
|
queryClient.setQueryData(['key', 2], 2)
|
|
518
|
-
const query1 = queryCache.find(['key', 1])!
|
|
419
|
+
const query1 = queryCache.find({ queryKey: ['key', 1] })!
|
|
519
420
|
|
|
520
421
|
const result = queryClient.getQueriesData({
|
|
521
422
|
predicate: (query) => query === query1,
|
|
@@ -535,10 +436,10 @@ describe('queryClient', () => {
|
|
|
535
436
|
Promise.resolve('data')
|
|
536
437
|
|
|
537
438
|
await expect(
|
|
538
|
-
queryClient.fetchQuery<StrictData, any, StrictData, StrictQueryKey>(
|
|
539
|
-
key,
|
|
540
|
-
fetchFn,
|
|
541
|
-
),
|
|
439
|
+
queryClient.fetchQuery<StrictData, any, StrictData, StrictQueryKey>({
|
|
440
|
+
queryKey: key,
|
|
441
|
+
queryFn: fetchFn,
|
|
442
|
+
}),
|
|
542
443
|
).resolves.toEqual('data')
|
|
543
444
|
})
|
|
544
445
|
|
|
@@ -547,8 +448,11 @@ describe('queryClient', () => {
|
|
|
547
448
|
const key = queryKey()
|
|
548
449
|
|
|
549
450
|
await expect(
|
|
550
|
-
queryClient.fetchQuery(
|
|
551
|
-
|
|
451
|
+
queryClient.fetchQuery({
|
|
452
|
+
queryKey: key,
|
|
453
|
+
queryFn: async (): Promise<unknown> => {
|
|
454
|
+
throw new Error('error')
|
|
455
|
+
},
|
|
552
456
|
}),
|
|
553
457
|
).rejects.toEqual(new Error('error'))
|
|
554
458
|
})
|
|
@@ -557,38 +461,44 @@ describe('queryClient', () => {
|
|
|
557
461
|
const key = queryKey()
|
|
558
462
|
|
|
559
463
|
const fetchFn = () => Promise.resolve('data')
|
|
560
|
-
const first = await queryClient.fetchQuery(
|
|
561
|
-
|
|
464
|
+
const first = await queryClient.fetchQuery({
|
|
465
|
+
queryKey: key,
|
|
466
|
+
queryFn: fetchFn,
|
|
467
|
+
})
|
|
468
|
+
const second = await queryClient.fetchQuery({
|
|
469
|
+
queryKey: key,
|
|
470
|
+
queryFn: fetchFn,
|
|
471
|
+
})
|
|
562
472
|
|
|
563
473
|
expect(second).toBe(first)
|
|
564
474
|
})
|
|
565
475
|
|
|
566
|
-
test('should be able to fetch when
|
|
476
|
+
test('should be able to fetch when garbage collection time is set to 0 and then be removed', async () => {
|
|
567
477
|
const key1 = queryKey()
|
|
568
|
-
const result = await queryClient.fetchQuery(
|
|
569
|
-
key1,
|
|
570
|
-
async () => {
|
|
478
|
+
const result = await queryClient.fetchQuery({
|
|
479
|
+
queryKey: key1,
|
|
480
|
+
queryFn: async () => {
|
|
571
481
|
await sleep(10)
|
|
572
482
|
return 1
|
|
573
483
|
},
|
|
574
|
-
|
|
575
|
-
)
|
|
484
|
+
gcTime: 0,
|
|
485
|
+
})
|
|
576
486
|
expect(result).toEqual(1)
|
|
577
487
|
await waitFor(() =>
|
|
578
488
|
expect(queryClient.getQueryData(key1)).toEqual(undefined),
|
|
579
489
|
)
|
|
580
490
|
})
|
|
581
491
|
|
|
582
|
-
test('should keep a query in cache if
|
|
492
|
+
test('should keep a query in cache if garbage collection time is Infinity', async () => {
|
|
583
493
|
const key1 = queryKey()
|
|
584
|
-
const result = await queryClient.fetchQuery(
|
|
585
|
-
key1,
|
|
586
|
-
async () => {
|
|
494
|
+
const result = await queryClient.fetchQuery({
|
|
495
|
+
queryKey: key1,
|
|
496
|
+
queryFn: async () => {
|
|
587
497
|
await sleep(10)
|
|
588
498
|
return 1
|
|
589
499
|
},
|
|
590
|
-
|
|
591
|
-
)
|
|
500
|
+
gcTime: Infinity,
|
|
501
|
+
})
|
|
592
502
|
const result2 = queryClient.getQueryData(key1)
|
|
593
503
|
expect(result).toEqual(1)
|
|
594
504
|
expect(result2).toEqual(1)
|
|
@@ -599,7 +509,9 @@ describe('queryClient', () => {
|
|
|
599
509
|
|
|
600
510
|
queryClient.setQueryData(key, 'og')
|
|
601
511
|
const fetchFn = () => Promise.resolve('new')
|
|
602
|
-
const first = await queryClient.fetchQuery(
|
|
512
|
+
const first = await queryClient.fetchQuery({
|
|
513
|
+
queryKey: key,
|
|
514
|
+
queryFn: fetchFn,
|
|
603
515
|
initialData: 'initial',
|
|
604
516
|
staleTime: 100,
|
|
605
517
|
})
|
|
@@ -613,18 +525,26 @@ describe('queryClient', () => {
|
|
|
613
525
|
const fetchFn = () => ++count
|
|
614
526
|
|
|
615
527
|
queryClient.setQueryData(key, count)
|
|
616
|
-
const first = await queryClient.fetchQuery(
|
|
528
|
+
const first = await queryClient.fetchQuery({
|
|
529
|
+
queryKey: key,
|
|
530
|
+
queryFn: fetchFn,
|
|
617
531
|
staleTime: 100,
|
|
618
532
|
})
|
|
619
533
|
await sleep(11)
|
|
620
|
-
const second = await queryClient.fetchQuery(
|
|
534
|
+
const second = await queryClient.fetchQuery({
|
|
535
|
+
queryKey: key,
|
|
536
|
+
queryFn: fetchFn,
|
|
621
537
|
staleTime: 10,
|
|
622
538
|
})
|
|
623
|
-
const third = await queryClient.fetchQuery(
|
|
539
|
+
const third = await queryClient.fetchQuery({
|
|
540
|
+
queryKey: key,
|
|
541
|
+
queryFn: fetchFn,
|
|
624
542
|
staleTime: 10,
|
|
625
543
|
})
|
|
626
544
|
await sleep(11)
|
|
627
|
-
const fourth = await queryClient.fetchQuery(
|
|
545
|
+
const fourth = await queryClient.fetchQuery({
|
|
546
|
+
queryKey: key,
|
|
547
|
+
queryFn: fetchFn,
|
|
628
548
|
staleTime: 10,
|
|
629
549
|
})
|
|
630
550
|
expect(first).toBe(0)
|
|
@@ -642,10 +562,10 @@ describe('queryClient', () => {
|
|
|
642
562
|
|
|
643
563
|
const data = {
|
|
644
564
|
pages: ['data'],
|
|
645
|
-
pageParams: [
|
|
565
|
+
pageParams: [0],
|
|
646
566
|
} as const
|
|
647
567
|
|
|
648
|
-
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
|
|
568
|
+
const fetchFn: QueryFunction<StrictData, StrictQueryKey, number> = () =>
|
|
649
569
|
Promise.resolve(data.pages[0])
|
|
650
570
|
|
|
651
571
|
await expect(
|
|
@@ -653,22 +573,24 @@ describe('queryClient', () => {
|
|
|
653
573
|
StrictData,
|
|
654
574
|
any,
|
|
655
575
|
StrictData,
|
|
656
|
-
StrictQueryKey
|
|
657
|
-
|
|
576
|
+
StrictQueryKey,
|
|
577
|
+
number
|
|
578
|
+
>({ queryKey: key, queryFn: fetchFn, defaultPageParam: 0 }),
|
|
658
579
|
).resolves.toEqual(data)
|
|
659
580
|
})
|
|
660
581
|
|
|
661
582
|
test('should return infinite query data', async () => {
|
|
662
583
|
const key = queryKey()
|
|
663
|
-
const result = await queryClient.fetchInfiniteQuery(
|
|
664
|
-
key,
|
|
665
|
-
|
|
666
|
-
|
|
584
|
+
const result = await queryClient.fetchInfiniteQuery({
|
|
585
|
+
queryKey: key,
|
|
586
|
+
defaultPageParam: 10,
|
|
587
|
+
queryFn: ({ pageParam }) => Number(pageParam),
|
|
588
|
+
})
|
|
667
589
|
const result2 = queryClient.getQueryData(key)
|
|
668
590
|
|
|
669
591
|
const expected = {
|
|
670
592
|
pages: [10],
|
|
671
|
-
pageParams: [
|
|
593
|
+
pageParams: [10],
|
|
672
594
|
}
|
|
673
595
|
|
|
674
596
|
expect(result).toEqual(expected)
|
|
@@ -682,36 +604,39 @@ describe('queryClient', () => {
|
|
|
682
604
|
type StrictQueryKey = ['strict', ...ReturnType<typeof queryKey>]
|
|
683
605
|
const key: StrictQueryKey = ['strict', ...queryKey()]
|
|
684
606
|
|
|
685
|
-
const fetchFn: QueryFunction<StrictData, StrictQueryKey> = () =>
|
|
607
|
+
const fetchFn: QueryFunction<StrictData, StrictQueryKey, number> = () =>
|
|
686
608
|
Promise.resolve('data')
|
|
687
609
|
|
|
688
610
|
await queryClient.prefetchInfiniteQuery<
|
|
689
611
|
StrictData,
|
|
690
612
|
any,
|
|
691
613
|
StrictData,
|
|
692
|
-
StrictQueryKey
|
|
693
|
-
|
|
614
|
+
StrictQueryKey,
|
|
615
|
+
number
|
|
616
|
+
>({ queryKey: key, queryFn: fetchFn, defaultPageParam: 0 })
|
|
694
617
|
|
|
695
618
|
const result = queryClient.getQueryData(key)
|
|
696
619
|
|
|
697
620
|
expect(result).toEqual({
|
|
698
621
|
pages: ['data'],
|
|
699
|
-
pageParams: [
|
|
622
|
+
pageParams: [0],
|
|
700
623
|
})
|
|
701
624
|
})
|
|
702
625
|
|
|
703
626
|
test('should return infinite query data', async () => {
|
|
704
627
|
const key = queryKey()
|
|
705
628
|
|
|
706
|
-
await queryClient.prefetchInfiniteQuery(
|
|
707
|
-
|
|
708
|
-
|
|
629
|
+
await queryClient.prefetchInfiniteQuery({
|
|
630
|
+
queryKey: key,
|
|
631
|
+
queryFn: ({ pageParam }) => Number(pageParam),
|
|
632
|
+
defaultPageParam: 10,
|
|
633
|
+
})
|
|
709
634
|
|
|
710
635
|
const result = queryClient.getQueryData(key)
|
|
711
636
|
|
|
712
637
|
expect(result).toEqual({
|
|
713
638
|
pages: [10],
|
|
714
|
-
pageParams: [
|
|
639
|
+
pageParams: [10],
|
|
715
640
|
})
|
|
716
641
|
})
|
|
717
642
|
})
|
|
@@ -730,7 +655,7 @@ describe('queryClient', () => {
|
|
|
730
655
|
any,
|
|
731
656
|
StrictData,
|
|
732
657
|
StrictQueryKey
|
|
733
|
-
>(key, fetchFn)
|
|
658
|
+
>({ queryKey: key, queryFn: fetchFn })
|
|
734
659
|
|
|
735
660
|
const result = queryClient.getQueryData(key)
|
|
736
661
|
|
|
@@ -740,33 +665,30 @@ describe('queryClient', () => {
|
|
|
740
665
|
test('should return undefined when an error is thrown', async () => {
|
|
741
666
|
const key = queryKey()
|
|
742
667
|
|
|
743
|
-
const result = await queryClient.prefetchQuery(
|
|
744
|
-
key,
|
|
745
|
-
async (): Promise<unknown> => {
|
|
668
|
+
const result = await queryClient.prefetchQuery({
|
|
669
|
+
queryKey: key,
|
|
670
|
+
queryFn: async (): Promise<unknown> => {
|
|
746
671
|
throw new Error('error')
|
|
747
672
|
},
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
},
|
|
751
|
-
)
|
|
673
|
+
retry: false,
|
|
674
|
+
})
|
|
752
675
|
|
|
753
676
|
expect(result).toBeUndefined()
|
|
754
|
-
expect(mockLogger.error).toHaveBeenCalled()
|
|
755
677
|
})
|
|
756
678
|
|
|
757
|
-
test('should be garbage collected after
|
|
679
|
+
test('should be garbage collected after gcTime if unused', async () => {
|
|
758
680
|
const key = queryKey()
|
|
759
681
|
|
|
760
|
-
await queryClient.prefetchQuery(
|
|
761
|
-
key,
|
|
762
|
-
async () => {
|
|
682
|
+
await queryClient.prefetchQuery({
|
|
683
|
+
queryKey: key,
|
|
684
|
+
queryFn: async () => {
|
|
763
685
|
return 'data'
|
|
764
686
|
},
|
|
765
|
-
|
|
766
|
-
)
|
|
767
|
-
expect(queryCache.find(key)).toBeDefined()
|
|
687
|
+
gcTime: 10,
|
|
688
|
+
})
|
|
689
|
+
expect(queryCache.find({ queryKey: key })).toBeDefined()
|
|
768
690
|
await sleep(15)
|
|
769
|
-
expect(queryCache.find(key)).not.toBeDefined()
|
|
691
|
+
expect(queryCache.find({ queryKey: key })).not.toBeDefined()
|
|
770
692
|
})
|
|
771
693
|
})
|
|
772
694
|
|
|
@@ -777,8 +699,8 @@ describe('queryClient', () => {
|
|
|
777
699
|
const fetchFn = () => Promise.resolve('data')
|
|
778
700
|
|
|
779
701
|
// check the query was added to the cache
|
|
780
|
-
await queryClient.prefetchQuery(key, fetchFn)
|
|
781
|
-
expect(queryCache.find(key)).toBeTruthy()
|
|
702
|
+
await queryClient.prefetchQuery({ queryKey: key, queryFn: fetchFn })
|
|
703
|
+
expect(queryCache.find({ queryKey: key })).toBeTruthy()
|
|
782
704
|
|
|
783
705
|
// check the error doesn't occur
|
|
784
706
|
expect(() =>
|
|
@@ -786,7 +708,7 @@ describe('queryClient', () => {
|
|
|
786
708
|
).not.toThrow()
|
|
787
709
|
|
|
788
710
|
// check query was successful removed
|
|
789
|
-
expect(queryCache.find(key)).toBeFalsy()
|
|
711
|
+
expect(queryCache.find({ queryKey: key })).toBeFalsy()
|
|
790
712
|
})
|
|
791
713
|
})
|
|
792
714
|
|
|
@@ -795,27 +717,42 @@ describe('queryClient', () => {
|
|
|
795
717
|
const key1 = queryKey()
|
|
796
718
|
const key2 = queryKey()
|
|
797
719
|
const key3 = queryKey()
|
|
798
|
-
await queryClient.fetchQuery(
|
|
799
|
-
|
|
720
|
+
await queryClient.fetchQuery({
|
|
721
|
+
queryKey: key1,
|
|
722
|
+
queryFn: async () => {
|
|
723
|
+
return 'data'
|
|
724
|
+
},
|
|
800
725
|
})
|
|
801
726
|
try {
|
|
802
|
-
await queryClient.fetchQuery(
|
|
803
|
-
|
|
727
|
+
await queryClient.fetchQuery({
|
|
728
|
+
queryKey: key2,
|
|
729
|
+
queryFn: async () => {
|
|
730
|
+
return Promise.reject<unknown>('err')
|
|
731
|
+
},
|
|
804
732
|
})
|
|
805
733
|
} catch {}
|
|
806
|
-
queryClient.fetchQuery(
|
|
807
|
-
|
|
808
|
-
|
|
734
|
+
queryClient.fetchQuery({
|
|
735
|
+
queryKey: key1,
|
|
736
|
+
queryFn: async () => {
|
|
737
|
+
await sleep(1000)
|
|
738
|
+
return 'data2'
|
|
739
|
+
},
|
|
809
740
|
})
|
|
810
741
|
try {
|
|
811
|
-
queryClient.fetchQuery(
|
|
812
|
-
|
|
813
|
-
|
|
742
|
+
queryClient.fetchQuery({
|
|
743
|
+
queryKey: key2,
|
|
744
|
+
queryFn: async () => {
|
|
745
|
+
await sleep(1000)
|
|
746
|
+
return Promise.reject<unknown>('err2')
|
|
747
|
+
},
|
|
814
748
|
})
|
|
815
749
|
} catch {}
|
|
816
|
-
queryClient.fetchQuery(
|
|
817
|
-
|
|
818
|
-
|
|
750
|
+
queryClient.fetchQuery({
|
|
751
|
+
queryKey: key3,
|
|
752
|
+
queryFn: async () => {
|
|
753
|
+
await sleep(1000)
|
|
754
|
+
return 'data3'
|
|
755
|
+
},
|
|
819
756
|
})
|
|
820
757
|
await sleep(10)
|
|
821
758
|
await queryClient.cancelQueries()
|
|
@@ -833,22 +770,28 @@ describe('queryClient', () => {
|
|
|
833
770
|
})
|
|
834
771
|
expect(state3).toMatchObject({
|
|
835
772
|
data: undefined,
|
|
836
|
-
status: '
|
|
773
|
+
status: 'pending',
|
|
837
774
|
fetchStatus: 'idle',
|
|
838
775
|
})
|
|
839
776
|
})
|
|
840
777
|
|
|
841
778
|
test('should not revert if revert option is set to false', async () => {
|
|
842
779
|
const key1 = queryKey()
|
|
843
|
-
await queryClient.fetchQuery(
|
|
844
|
-
|
|
780
|
+
await queryClient.fetchQuery({
|
|
781
|
+
queryKey: key1,
|
|
782
|
+
queryFn: async () => {
|
|
783
|
+
return 'data'
|
|
784
|
+
},
|
|
845
785
|
})
|
|
846
|
-
queryClient.fetchQuery(
|
|
847
|
-
|
|
848
|
-
|
|
786
|
+
queryClient.fetchQuery({
|
|
787
|
+
queryKey: key1,
|
|
788
|
+
queryFn: async () => {
|
|
789
|
+
await sleep(1000)
|
|
790
|
+
return 'data2'
|
|
791
|
+
},
|
|
849
792
|
})
|
|
850
793
|
await sleep(10)
|
|
851
|
-
await queryClient.cancelQueries(key1
|
|
794
|
+
await queryClient.cancelQueries({ queryKey: key1 }, { revert: false })
|
|
852
795
|
const state1 = queryClient.getQueryState(key1)
|
|
853
796
|
expect(state1).toMatchObject({
|
|
854
797
|
status: 'error',
|
|
@@ -860,7 +803,7 @@ describe('queryClient', () => {
|
|
|
860
803
|
test('should not refetch if all observers are disabled', async () => {
|
|
861
804
|
const key = queryKey()
|
|
862
805
|
const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
|
|
863
|
-
await queryClient.fetchQuery(key, queryFn)
|
|
806
|
+
await queryClient.fetchQuery({ queryKey: key, queryFn })
|
|
864
807
|
const observer1 = new QueryObserver(queryClient, {
|
|
865
808
|
queryKey: key,
|
|
866
809
|
queryFn,
|
|
@@ -874,7 +817,7 @@ describe('queryClient', () => {
|
|
|
874
817
|
test('should refetch if at least one observer is enabled', async () => {
|
|
875
818
|
const key = queryKey()
|
|
876
819
|
const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
|
|
877
|
-
await queryClient.fetchQuery(key, queryFn)
|
|
820
|
+
await queryClient.fetchQuery({ queryKey: key, queryFn })
|
|
878
821
|
const observer1 = new QueryObserver(queryClient, {
|
|
879
822
|
queryKey: key,
|
|
880
823
|
queryFn,
|
|
@@ -897,8 +840,8 @@ describe('queryClient', () => {
|
|
|
897
840
|
const key2 = queryKey()
|
|
898
841
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
899
842
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
900
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
901
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
843
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
844
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
902
845
|
const observer1 = new QueryObserver(queryClient, {
|
|
903
846
|
queryKey: key1,
|
|
904
847
|
staleTime: Infinity,
|
|
@@ -923,8 +866,8 @@ describe('queryClient', () => {
|
|
|
923
866
|
const key2 = queryKey()
|
|
924
867
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
925
868
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
926
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
927
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
869
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
870
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
928
871
|
const observer = new QueryObserver(queryClient, {
|
|
929
872
|
queryKey: key1,
|
|
930
873
|
queryFn: queryFn1,
|
|
@@ -942,14 +885,14 @@ describe('queryClient', () => {
|
|
|
942
885
|
const key2 = queryKey()
|
|
943
886
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
944
887
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
945
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
946
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
888
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
889
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
947
890
|
const observer = new QueryObserver(queryClient, {
|
|
948
891
|
queryKey: key1,
|
|
949
892
|
queryFn: queryFn1,
|
|
950
893
|
})
|
|
951
894
|
const unsubscribe = observer.subscribe(() => undefined)
|
|
952
|
-
queryClient.invalidateQueries(key1)
|
|
895
|
+
queryClient.invalidateQueries({ queryKey: key1 })
|
|
953
896
|
await queryClient.refetchQueries({ stale: true })
|
|
954
897
|
unsubscribe()
|
|
955
898
|
// fetchQuery, observer mount, invalidation (cancels observer mount) and refetch
|
|
@@ -962,9 +905,9 @@ describe('queryClient', () => {
|
|
|
962
905
|
const key2 = queryKey()
|
|
963
906
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
964
907
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
965
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
966
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
967
|
-
queryClient.invalidateQueries(key1)
|
|
908
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
909
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
910
|
+
queryClient.invalidateQueries({ queryKey: key1 })
|
|
968
911
|
const observer = new QueryObserver(queryClient, {
|
|
969
912
|
queryKey: key1,
|
|
970
913
|
queryFn: queryFn1,
|
|
@@ -984,8 +927,8 @@ describe('queryClient', () => {
|
|
|
984
927
|
const key2 = queryKey()
|
|
985
928
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
986
929
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
987
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
988
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
930
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
931
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
989
932
|
const observer = new QueryObserver(queryClient, {
|
|
990
933
|
queryKey: key1,
|
|
991
934
|
queryFn: queryFn1,
|
|
@@ -1003,8 +946,8 @@ describe('queryClient', () => {
|
|
|
1003
946
|
const key2 = queryKey()
|
|
1004
947
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1005
948
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1006
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1007
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
949
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
950
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1008
951
|
const observer = new QueryObserver(queryClient, {
|
|
1009
952
|
queryKey: key1,
|
|
1010
953
|
queryFn: queryFn1,
|
|
@@ -1022,8 +965,8 @@ describe('queryClient', () => {
|
|
|
1022
965
|
const key2 = queryKey()
|
|
1023
966
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1024
967
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1025
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1026
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
968
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
969
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1027
970
|
const observer = new QueryObserver(queryClient, {
|
|
1028
971
|
queryKey: key1,
|
|
1029
972
|
queryFn: queryFn1,
|
|
@@ -1041,8 +984,8 @@ describe('queryClient', () => {
|
|
|
1041
984
|
const key2 = queryKey()
|
|
1042
985
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1043
986
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1044
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1045
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
987
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
988
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1046
989
|
const observer = new QueryObserver(queryClient, {
|
|
1047
990
|
queryKey: key1,
|
|
1048
991
|
queryFn: queryFn1,
|
|
@@ -1084,15 +1027,15 @@ describe('queryClient', () => {
|
|
|
1084
1027
|
const key2 = queryKey()
|
|
1085
1028
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1086
1029
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1087
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1088
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
1030
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
1031
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1089
1032
|
const observer = new QueryObserver(queryClient, {
|
|
1090
1033
|
queryKey: key1,
|
|
1091
1034
|
queryFn: queryFn1,
|
|
1092
1035
|
staleTime: Infinity,
|
|
1093
1036
|
})
|
|
1094
1037
|
const unsubscribe = observer.subscribe(() => undefined)
|
|
1095
|
-
queryClient.invalidateQueries(key1)
|
|
1038
|
+
queryClient.invalidateQueries({ queryKey: key1 })
|
|
1096
1039
|
unsubscribe()
|
|
1097
1040
|
expect(queryFn1).toHaveBeenCalledTimes(2)
|
|
1098
1041
|
expect(queryFn2).toHaveBeenCalledTimes(1)
|
|
@@ -1103,15 +1046,15 @@ describe('queryClient', () => {
|
|
|
1103
1046
|
const key2 = queryKey()
|
|
1104
1047
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1105
1048
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1106
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1107
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
1049
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
1050
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1108
1051
|
const observer = new QueryObserver(queryClient, {
|
|
1109
1052
|
queryKey: key1,
|
|
1110
1053
|
enabled: false,
|
|
1111
1054
|
staleTime: Infinity,
|
|
1112
1055
|
})
|
|
1113
1056
|
const unsubscribe = observer.subscribe(() => undefined)
|
|
1114
|
-
queryClient.invalidateQueries(key1)
|
|
1057
|
+
queryClient.invalidateQueries({ queryKey: key1 })
|
|
1115
1058
|
unsubscribe()
|
|
1116
1059
|
expect(queryFn1).toHaveBeenCalledTimes(1)
|
|
1117
1060
|
expect(queryFn2).toHaveBeenCalledTimes(1)
|
|
@@ -1122,15 +1065,16 @@ describe('queryClient', () => {
|
|
|
1122
1065
|
const key2 = queryKey()
|
|
1123
1066
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1124
1067
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1125
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1126
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
1068
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
1069
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1127
1070
|
const observer = new QueryObserver(queryClient, {
|
|
1128
1071
|
queryKey: key1,
|
|
1129
1072
|
queryFn: queryFn1,
|
|
1130
1073
|
staleTime: Infinity,
|
|
1131
1074
|
})
|
|
1132
1075
|
const unsubscribe = observer.subscribe(() => undefined)
|
|
1133
|
-
queryClient.invalidateQueries(
|
|
1076
|
+
queryClient.invalidateQueries({
|
|
1077
|
+
queryKey: key1,
|
|
1134
1078
|
refetchType: 'none',
|
|
1135
1079
|
})
|
|
1136
1080
|
unsubscribe()
|
|
@@ -1143,8 +1087,8 @@ describe('queryClient', () => {
|
|
|
1143
1087
|
const key2 = queryKey()
|
|
1144
1088
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1145
1089
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1146
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1147
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
1090
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
1091
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1148
1092
|
const observer = new QueryObserver(queryClient, {
|
|
1149
1093
|
queryKey: key1,
|
|
1150
1094
|
queryFn: queryFn1,
|
|
@@ -1154,7 +1098,8 @@ describe('queryClient', () => {
|
|
|
1154
1098
|
const unsubscribe = observer.subscribe(() => undefined)
|
|
1155
1099
|
unsubscribe()
|
|
1156
1100
|
|
|
1157
|
-
await queryClient.invalidateQueries(
|
|
1101
|
+
await queryClient.invalidateQueries({
|
|
1102
|
+
queryKey: key1,
|
|
1158
1103
|
refetchType: 'inactive',
|
|
1159
1104
|
})
|
|
1160
1105
|
expect(queryFn1).toHaveBeenCalledTimes(2)
|
|
@@ -1166,8 +1111,8 @@ describe('queryClient', () => {
|
|
|
1166
1111
|
const key2 = queryKey()
|
|
1167
1112
|
const queryFn1 = jest.fn<string, unknown[]>().mockReturnValue('data1')
|
|
1168
1113
|
const queryFn2 = jest.fn<string, unknown[]>().mockReturnValue('data2')
|
|
1169
|
-
await queryClient.fetchQuery(key1, queryFn1)
|
|
1170
|
-
await queryClient.fetchQuery(key2, queryFn2)
|
|
1114
|
+
await queryClient.fetchQuery({ queryKey: key1, queryFn: queryFn1 })
|
|
1115
|
+
await queryClient.fetchQuery({ queryKey: key2, queryFn: queryFn2 })
|
|
1171
1116
|
const observer = new QueryObserver(queryClient, {
|
|
1172
1117
|
queryKey: key1,
|
|
1173
1118
|
queryFn: queryFn1,
|
|
@@ -1192,9 +1137,7 @@ describe('queryClient', () => {
|
|
|
1192
1137
|
return new Promise((resolve) => {
|
|
1193
1138
|
fetchCount++
|
|
1194
1139
|
setTimeout(() => resolve(5), 10)
|
|
1195
|
-
|
|
1196
|
-
signal.addEventListener('abort', abortFn)
|
|
1197
|
-
}
|
|
1140
|
+
signal.addEventListener('abort', abortFn)
|
|
1198
1141
|
})
|
|
1199
1142
|
},
|
|
1200
1143
|
initialData: 1,
|
|
@@ -1217,9 +1160,7 @@ describe('queryClient', () => {
|
|
|
1217
1160
|
return new Promise((resolve) => {
|
|
1218
1161
|
fetchCount++
|
|
1219
1162
|
setTimeout(() => resolve(5), 10)
|
|
1220
|
-
|
|
1221
|
-
signal.addEventListener('abort', abortFn)
|
|
1222
|
-
}
|
|
1163
|
+
signal.addEventListener('abort', abortFn)
|
|
1223
1164
|
})
|
|
1224
1165
|
},
|
|
1225
1166
|
initialData: 1,
|
|
@@ -1239,11 +1180,11 @@ describe('queryClient', () => {
|
|
|
1239
1180
|
|
|
1240
1181
|
const callback = jest.fn()
|
|
1241
1182
|
|
|
1242
|
-
await queryClient.prefetchQuery(key, () => 'data')
|
|
1183
|
+
await queryClient.prefetchQuery({ queryKey: key, queryFn: () => 'data' })
|
|
1243
1184
|
|
|
1244
1185
|
queryCache.subscribe(callback)
|
|
1245
1186
|
|
|
1246
|
-
queryClient.resetQueries(key)
|
|
1187
|
+
queryClient.resetQueries({ queryKey: key })
|
|
1247
1188
|
|
|
1248
1189
|
expect(callback).toHaveBeenCalled()
|
|
1249
1190
|
})
|
|
@@ -1251,33 +1192,35 @@ describe('queryClient', () => {
|
|
|
1251
1192
|
test('should reset query', async () => {
|
|
1252
1193
|
const key = queryKey()
|
|
1253
1194
|
|
|
1254
|
-
await queryClient.prefetchQuery(key, () => 'data')
|
|
1195
|
+
await queryClient.prefetchQuery({ queryKey: key, queryFn: () => 'data' })
|
|
1255
1196
|
|
|
1256
1197
|
let state = queryClient.getQueryState(key)
|
|
1257
1198
|
expect(state?.data).toEqual('data')
|
|
1258
1199
|
expect(state?.status).toEqual('success')
|
|
1259
1200
|
|
|
1260
|
-
queryClient.resetQueries(key)
|
|
1201
|
+
queryClient.resetQueries({ queryKey: key })
|
|
1261
1202
|
|
|
1262
1203
|
state = queryClient.getQueryState(key)
|
|
1263
1204
|
|
|
1264
1205
|
expect(state).toBeTruthy()
|
|
1265
1206
|
expect(state?.data).toBeUndefined()
|
|
1266
|
-
expect(state?.status).toEqual('
|
|
1207
|
+
expect(state?.status).toEqual('pending')
|
|
1267
1208
|
expect(state?.fetchStatus).toEqual('idle')
|
|
1268
1209
|
})
|
|
1269
1210
|
|
|
1270
1211
|
test('should reset query data to initial data if set', async () => {
|
|
1271
1212
|
const key = queryKey()
|
|
1272
1213
|
|
|
1273
|
-
await queryClient.prefetchQuery(
|
|
1214
|
+
await queryClient.prefetchQuery({
|
|
1215
|
+
queryKey: key,
|
|
1216
|
+
queryFn: () => 'data',
|
|
1274
1217
|
initialData: 'initial',
|
|
1275
1218
|
})
|
|
1276
1219
|
|
|
1277
1220
|
let state = queryClient.getQueryState(key)
|
|
1278
1221
|
expect(state?.data).toEqual('data')
|
|
1279
1222
|
|
|
1280
|
-
queryClient.resetQueries(key)
|
|
1223
|
+
queryClient.resetQueries({ queryKey: key })
|
|
1281
1224
|
|
|
1282
1225
|
state = queryClient.getQueryState(key)
|
|
1283
1226
|
|
|
@@ -1310,98 +1253,6 @@ describe('queryClient', () => {
|
|
|
1310
1253
|
})
|
|
1311
1254
|
})
|
|
1312
1255
|
|
|
1313
|
-
describe('refetch only certain pages of an infinite query', () => {
|
|
1314
|
-
test('refetchQueries', async () => {
|
|
1315
|
-
const key = queryKey()
|
|
1316
|
-
let multiplier = 1
|
|
1317
|
-
const observer = new InfiniteQueryObserver<number>(queryClient, {
|
|
1318
|
-
queryKey: key,
|
|
1319
|
-
queryFn: ({ pageParam = 10 }) => Number(pageParam) * multiplier,
|
|
1320
|
-
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1321
|
-
})
|
|
1322
|
-
|
|
1323
|
-
await observer.fetchNextPage()
|
|
1324
|
-
await observer.fetchNextPage()
|
|
1325
|
-
|
|
1326
|
-
expect(queryClient.getQueryData(key)).toMatchObject({
|
|
1327
|
-
pages: [10, 11],
|
|
1328
|
-
})
|
|
1329
|
-
|
|
1330
|
-
multiplier = 2
|
|
1331
|
-
|
|
1332
|
-
await queryClient.refetchQueries({
|
|
1333
|
-
queryKey: key,
|
|
1334
|
-
refetchPage: (_, index) => index === 0,
|
|
1335
|
-
})
|
|
1336
|
-
|
|
1337
|
-
expect(queryClient.getQueryData(key)).toMatchObject({
|
|
1338
|
-
pages: [20, 11],
|
|
1339
|
-
})
|
|
1340
|
-
})
|
|
1341
|
-
test('invalidateQueries', async () => {
|
|
1342
|
-
const key = queryKey()
|
|
1343
|
-
let multiplier = 1
|
|
1344
|
-
const observer = new InfiniteQueryObserver<number>(queryClient, {
|
|
1345
|
-
queryKey: key,
|
|
1346
|
-
queryFn: ({ pageParam = 10 }) => Number(pageParam) * multiplier,
|
|
1347
|
-
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1348
|
-
})
|
|
1349
|
-
|
|
1350
|
-
await observer.fetchNextPage()
|
|
1351
|
-
await observer.fetchNextPage()
|
|
1352
|
-
|
|
1353
|
-
expect(queryClient.getQueryData(key)).toMatchObject({
|
|
1354
|
-
pages: [10, 11],
|
|
1355
|
-
})
|
|
1356
|
-
|
|
1357
|
-
multiplier = 2
|
|
1358
|
-
|
|
1359
|
-
await queryClient.invalidateQueries({
|
|
1360
|
-
queryKey: key,
|
|
1361
|
-
refetchType: 'all',
|
|
1362
|
-
refetchPage: (page, _, allPages) => {
|
|
1363
|
-
return page === allPages[0]
|
|
1364
|
-
},
|
|
1365
|
-
})
|
|
1366
|
-
|
|
1367
|
-
expect(queryClient.getQueryData(key)).toMatchObject({
|
|
1368
|
-
pages: [20, 11],
|
|
1369
|
-
})
|
|
1370
|
-
})
|
|
1371
|
-
|
|
1372
|
-
test('resetQueries', async () => {
|
|
1373
|
-
const key = queryKey()
|
|
1374
|
-
let multiplier = 1
|
|
1375
|
-
new InfiniteQueryObserver<number>(queryClient, {
|
|
1376
|
-
queryKey: key,
|
|
1377
|
-
queryFn: ({ pageParam = 10 }) => Number(pageParam) * multiplier,
|
|
1378
|
-
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1379
|
-
initialData: () => ({
|
|
1380
|
-
pages: [10, 11],
|
|
1381
|
-
pageParams: [10, 11],
|
|
1382
|
-
}),
|
|
1383
|
-
})
|
|
1384
|
-
|
|
1385
|
-
expect(queryClient.getQueryData(key)).toMatchObject({
|
|
1386
|
-
pages: [10, 11],
|
|
1387
|
-
})
|
|
1388
|
-
|
|
1389
|
-
multiplier = 2
|
|
1390
|
-
|
|
1391
|
-
await queryClient.resetQueries({
|
|
1392
|
-
queryKey: key,
|
|
1393
|
-
type: 'inactive',
|
|
1394
|
-
refetchPage: (page, _, allPages) => {
|
|
1395
|
-
return page === allPages[0]
|
|
1396
|
-
},
|
|
1397
|
-
})
|
|
1398
|
-
|
|
1399
|
-
expect(queryClient.getQueryData(key)).toMatchObject({
|
|
1400
|
-
pages: [20, 11],
|
|
1401
|
-
})
|
|
1402
|
-
})
|
|
1403
|
-
})
|
|
1404
|
-
|
|
1405
1256
|
describe('focusManager and onlineManager', () => {
|
|
1406
1257
|
test('should notify queryCache and mutationCache if focused', async () => {
|
|
1407
1258
|
const testClient = createQueryClient()
|