Open History to see the last commit
1import { ref } from 'vue-demi'
2import { QueryClient as QueryClientOrigin } from '@tanstack/query-core'
3β
4import { QueryClient } from '../queryClient'
5β
6jest.mock('@tanstack/query-core')
7β
8const queryKeyRef = ['foo', ref('bar')]
9const queryKeyUnref = ['foo', 'bar']
10β
11const fn = () => 'mock'
12β
13describe('QueryCache', () => {
14 // beforeAll(() => {
15 // jest.spyOn(QueryCacheOrigin.prototype, "find");
16 // jest.spyOn(QueryCacheOrigin.prototype, "findAll");
17 // });
18β
19 describe('isFetching', () => {
20 test('should properly unwrap 1 parameter', async () => {
21 const queryClient = new QueryClient()
22β
23 queryClient.isFetching({
24 queryKey: queryKeyRef,
25 })
26β
27 expect(QueryClientOrigin.prototype.isFetching).toBeCalledWith({
28 queryKey: queryKeyUnref,
29 })
30 })
31β
32 test('should properly unwrap 2 parameters', async () => {
33 const queryClient = new QueryClient()
34β
35 queryClient.isFetching(queryKeyRef, {
36 queryKey: queryKeyRef,
37 })
38β
39 expect(QueryClientOrigin.prototype.isFetching).toBeCalledWith(
40 queryKeyUnref,
41 {
42 queryKey: queryKeyUnref,
43 },
44 )
45 })
46 })
47β
48 describe('isMutating', () => {
49 test('should properly unwrap 1 parameter', async () => {
50 const queryClient = new QueryClient()
51β
52 queryClient.isMutating({
53 mutationKey: queryKeyRef,
54 })
55β
56 expect(QueryClientOrigin.prototype.isMutating).toBeCalledWith({
57 mutationKey: queryKeyUnref,
58 })
59 })
60 })
61β
62 describe('getQueryData', () => {
63 test('should properly unwrap 2 parameter', async () => {
64 const queryClient = new QueryClient()
65β
66 queryClient.getQueryData(queryKeyRef, {
67 queryKey: queryKeyRef,
68 })
69β
70 expect(QueryClientOrigin.prototype.getQueryData).toBeCalledWith(
71 queryKeyUnref,
72 {
73 queryKey: queryKeyUnref,
74 },
75 )
76 })
77 })
78β
79 describe('getQueriesData', () => {
80 test('should properly unwrap queryKey param', async () => {
81 const queryClient = new QueryClient()
82β
83 queryClient.getQueriesData(queryKeyRef)
84β
85 expect(QueryClientOrigin.prototype.getQueriesData).toBeCalledWith(
86 queryKeyUnref,
87 )
88 })
89β
90 test('should properly unwrap filters param', async () => {
91 const queryClient = new QueryClient()
92β
93 queryClient.getQueriesData({ queryKey: queryKeyRef })
94β
95 expect(QueryClientOrigin.prototype.getQueriesData).toBeCalledWith({
96 queryKey: queryKeyUnref,
97 })
98 })
99 })
100β
101 describe('setQueryData', () => {
102 test('should properly unwrap 3 parameter', async () => {
103 const queryClient = new QueryClient()
104β
105 queryClient.setQueryData(queryKeyRef, fn, { updatedAt: ref(3) })
106β
107 expect(QueryClientOrigin.prototype.setQueryData).toBeCalledWith(
108 queryKeyUnref,
109 fn,
110 { updatedAt: 3 },
111 )
112 })
113 })
114β
115 describe('setQueriesData', () => {
116 test('should properly unwrap params with queryKey', async () => {
117 const queryClient = new QueryClient()
118β
119 queryClient.setQueriesData(queryKeyRef, fn, { updatedAt: ref(3) })
120β
121 expect(QueryClientOrigin.prototype.setQueriesData).toBeCalledWith(
122 queryKeyUnref,
123 fn,
124 { updatedAt: 3 },
125 )
126 })
127β
128 test('should properly unwrap params with filters', async () => {
129 const queryClient = new QueryClient()
130β
131 queryClient.setQueriesData({ queryKey: queryKeyRef }, fn, {
132 updatedAt: ref(3),
133 })
134β
135 expect(QueryClientOrigin.prototype.setQueriesData).toBeCalledWith(
136 { queryKey: queryKeyUnref },
137 fn,
138 { updatedAt: 3 },
139 )
140 })
141 })
142β
143 describe('getQueryState', () => {
144 test('should properly unwrap 2 parameter', async () => {
145 const queryClient = new QueryClient()
146β
147 queryClient.getQueryState(queryKeyRef, { queryKey: queryKeyRef })
148β
149 expect(QueryClientOrigin.prototype.getQueryState).toBeCalledWith(
150 queryKeyUnref,
151 { queryKey: queryKeyUnref },
152 )
153 })
154 })
155β
156 describe('removeQueries', () => {
157 test('should properly unwrap 1 parameter', async () => {
158 const queryClient = new QueryClient()
159β
160 queryClient.removeQueries({
161 queryKey: queryKeyRef,
162 })
163β
164 expect(QueryClientOrigin.prototype.removeQueries).toBeCalledWith({
165 queryKey: queryKeyUnref,
166 })
167 })
168β
169 test('should properly unwrap 2 parameter', async () => {
170 const queryClient = new QueryClient()
171β
172 queryClient.removeQueries(queryKeyRef, {
173 queryKey: queryKeyRef,
174 })
175β
176 expect(QueryClientOrigin.prototype.removeQueries).toBeCalledWith(
177 queryKeyUnref,
178 {
179 queryKey: queryKeyUnref,
180 },
181 )
182 })
183 })
184β
185 describe('resetQueries', () => {
186 test('should properly unwrap 2 parameter', async () => {
187 const queryClient = new QueryClient()
188β
189 queryClient.resetQueries(
190 {
191 queryKey: queryKeyRef,
192 },
193 { cancelRefetch: ref(false) },
194 )
195β
196 expect(QueryClientOrigin.prototype.resetQueries).toBeCalledWith(
197 {
198 queryKey: queryKeyUnref,
199 },
200 { cancelRefetch: false },
201 )
202 })
203β
204 test('should properly unwrap 3 parameters', async () => {
205 const queryClient = new QueryClient()
206β
207 queryClient.resetQueries(
208 queryKeyRef,
209 {
210 queryKey: queryKeyRef,
211 },
212 { cancelRefetch: ref(false) },
213 )
214β
215 expect(QueryClientOrigin.prototype.resetQueries).toBeCalledWith(
216 queryKeyUnref,
217 {
218 queryKey: queryKeyUnref,
219 },
220 { cancelRefetch: false },
221 )
222 })
223 })
224β
225 describe('cancelQueries', () => {
226 test('should properly unwrap 2 parameter', async () => {
227 const queryClient = new QueryClient()
228β
229 queryClient.cancelQueries(
230 {
231 queryKey: queryKeyRef,
232 },
233 { revert: ref(false) },
234 )
235β
236 expect(QueryClientOrigin.prototype.cancelQueries).toBeCalledWith(
237 {
238 queryKey: queryKeyUnref,
239 },
240 { revert: false },
241 )
242 })
243β
244 test('should properly unwrap 3 parameters', async () => {
245 const queryClient = new QueryClient()
246β
247 queryClient.cancelQueries(
248 queryKeyRef,
249 {
250 queryKey: queryKeyRef,
251 },
252 { revert: ref(false) },
253 )
254β
255 expect(QueryClientOrigin.prototype.cancelQueries).toBeCalledWith(
256 queryKeyUnref,
257 {
258 queryKey: queryKeyUnref,
259 },
260 { revert: false },
261 )
262 })
263 })
264β
265 describe('invalidateQueries', () => {
266 test('should properly unwrap 2 parameter', async () => {
267 const queryClient = new QueryClient()
268β
269 queryClient.invalidateQueries(
270 {
271 queryKey: queryKeyRef,
272 },
273 { cancelRefetch: ref(false) },
274 )
275β
276 expect(QueryClientOrigin.prototype.invalidateQueries).toBeCalledWith(
277 {
278 queryKey: queryKeyUnref,
279 },
280 { cancelRefetch: false },
281 )
282 })
283β
284 test('should properly unwrap 3 parameters', async () => {
285 const queryClient = new QueryClient()
286β
287 queryClient.invalidateQueries(
288 queryKeyRef,
289 {
290 queryKey: queryKeyRef,
291 },
292 { cancelRefetch: ref(false) },
293 )
294β
295 expect(QueryClientOrigin.prototype.invalidateQueries).toBeCalledWith(
296 queryKeyUnref,
297 {
298 queryKey: queryKeyUnref,
299 },
300 { cancelRefetch: false },
301 )
302 })
303 })
304β
305 describe('refetchQueries', () => {
306 test('should properly unwrap 2 parameter', async () => {
307 const queryClient = new QueryClient()
308β
309 queryClient.refetchQueries(
310 {
311 queryKey: queryKeyRef,
312 },
313 { cancelRefetch: ref(false) },
314 )
315β
316 expect(QueryClientOrigin.prototype.refetchQueries).toBeCalledWith(
317 {
318 queryKey: queryKeyUnref,
319 },
320 { cancelRefetch: false },
321 )
322 })
323β
324 test('should properly unwrap 3 parameters', async () => {
325 const queryClient = new QueryClient()
326β
327 queryClient.refetchQueries(
328 queryKeyRef,
329 {
330 queryKey: queryKeyRef,
331 },
332 { cancelRefetch: ref(false) },
333 )
334β
335 expect(QueryClientOrigin.prototype.refetchQueries).toBeCalledWith(
336 queryKeyUnref,
337 {
338 queryKey: queryKeyUnref,
339 },
340 { cancelRefetch: false },
341 )
342 })
343 })
344β
345 describe('fetchQuery', () => {
346 test('should properly unwrap 1 parameter', async () => {
347 const queryClient = new QueryClient()
348β
349 queryClient.fetchQuery({
350 queryKey: queryKeyRef,
351 })
352β
353 expect(QueryClientOrigin.prototype.fetchQuery).toBeCalledWith({
354 queryKey: queryKeyUnref,
355 })
356 })
357β
358 test('should properly unwrap 2 parameters', async () => {
359 const queryClient = new QueryClient()
360β
361 queryClient.fetchQuery(queryKeyRef, {
362 queryKey: queryKeyRef,
363 })
364β
365 expect(QueryClientOrigin.prototype.fetchQuery).toBeCalledWith(
366 queryKeyUnref,
367 {
368 queryKey: queryKeyUnref,
369 },
370 undefined,
371 )
372 })
373β
374 test('should properly unwrap 3 parameters', async () => {
375 const queryClient = new QueryClient()
376β
377 queryClient.fetchQuery(queryKeyRef, fn, {
378 queryKey: queryKeyRef,
379 })
380β
381 expect(QueryClientOrigin.prototype.fetchQuery).toBeCalledWith(
382 queryKeyUnref,
383 fn,
384 {
385 queryKey: queryKeyUnref,
386 },
387 )
388 })
389 })
390β
391 describe('prefetchQuery', () => {
392 test('should properly unwrap parameters', async () => {
393 const queryClient = new QueryClient()
394β
395 queryClient.prefetchQuery(queryKeyRef, fn, { queryKey: queryKeyRef })
396β
397 expect(QueryClientOrigin.prototype.prefetchQuery).toBeCalledWith(
398 queryKeyUnref,
399 fn,
400 {
401 queryKey: queryKeyUnref,
402 },
403 )
404 })
405 })
406β
407 describe('fetchInfiniteQuery', () => {
408 test('should properly unwrap 1 parameter', async () => {
409 const queryClient = new QueryClient()
410β
411 queryClient.fetchInfiniteQuery({
412 queryKey: queryKeyRef,
413 })
414β
415 expect(QueryClientOrigin.prototype.fetchInfiniteQuery).toBeCalledWith({
416 queryKey: queryKeyUnref,
417 })
418 })
419β
420 test('should properly unwrap 2 parameters', async () => {
421 const queryClient = new QueryClient()
422β
423 queryClient.fetchInfiniteQuery(queryKeyRef, {
424 queryKey: queryKeyRef,
425 })
426β
427 expect(QueryClientOrigin.prototype.fetchInfiniteQuery).toBeCalledWith(
428 queryKeyUnref,
429 {
430 queryKey: queryKeyUnref,
431 },
432 undefined,
433 )
434 })
435β
436 test('should properly unwrap 3 parameters', async () => {
437 const queryClient = new QueryClient()
438β
439 queryClient.fetchInfiniteQuery(queryKeyRef, fn, {
440 queryKey: queryKeyRef,
441 })
442β
443 expect(QueryClientOrigin.prototype.fetchInfiniteQuery).toBeCalledWith(
444 queryKeyUnref,
445 fn,
446 {
447 queryKey: queryKeyUnref,
448 },
449 )
450 })
451 })
452β
453 describe('prefetchInfiniteQuery', () => {
454 test('should properly unwrap parameters', async () => {
455 const queryClient = new QueryClient()
456β
457 queryClient.prefetchInfiniteQuery(queryKeyRef, fn, {
458 queryKey: queryKeyRef,
459 })
460β
461 expect(QueryClientOrigin.prototype.prefetchInfiniteQuery).toBeCalledWith(
462 queryKeyUnref,
463 fn,
464 {
465 queryKey: queryKeyUnref,
466 },
467 )
468 })
469 })
470β
471 describe('setDefaultOptions', () => {
472 test('should properly unwrap parameters', async () => {
473 const queryClient = new QueryClient()
474β
475 queryClient.setDefaultOptions({
476 queries: {
477 enabled: ref(false),
478 },
479 })
480β
481 expect(QueryClientOrigin.prototype.setDefaultOptions).toBeCalledWith({
482 queries: {
483 enabled: false,
484 },
485 })
486 })
487 })
488β
489 describe('setQueryDefaults', () => {
490 test('should properly unwrap parameters', async () => {
491 const queryClient = new QueryClient()
492β
493 queryClient.setQueryDefaults(queryKeyRef, {
494 enabled: ref(false),
495 })
496β
497 expect(QueryClientOrigin.prototype.setQueryDefaults).toBeCalledWith(
498 queryKeyUnref,
499 {
500 enabled: false,
501 },
502 )
503 })
504 })
505β
506 describe('getQueryDefaults', () => {
507 test('should properly unwrap parameters', async () => {
508 const queryClient = new QueryClient()
509β
510 queryClient.getQueryDefaults(queryKeyRef)
511β
512 expect(QueryClientOrigin.prototype.getQueryDefaults).toBeCalledWith(
513 queryKeyUnref,
514 )
515 })
516 })
517β
518 describe('setMutationDefaults', () => {
519 test('should properly unwrap parameters', async () => {
520 const queryClient = new QueryClient()
521β
522 queryClient.setMutationDefaults(queryKeyRef, {
523 mutationKey: queryKeyRef,
524 })
525β
526 expect(QueryClientOrigin.prototype.setMutationDefaults).toBeCalledWith(
527 queryKeyUnref,
528 {
529 mutationKey: queryKeyUnref,
530 },
531 )
532 })
533 })
534β
535 describe('getMutationDefaults', () => {
536 test('should properly unwrap parameters', async () => {
537 const queryClient = new QueryClient()
538β
539 queryClient.getMutationDefaults(queryKeyRef)
540β
541 expect(QueryClientOrigin.prototype.getMutationDefaults).toBeCalledWith(
542 queryKeyUnref,
543 )
544 })
545 })
546})