Open History to see the last commit
1import { ref } from 'vue-demi'
2import { QueryClient as QueryClientOrigin } from '@tanstack/query-core'
3β
4import { vi } from 'vitest'
5import { QueryClient } from '../queryClient'
6β
7vi.mock('@tanstack/query-core')
8β
9const queryKeyRef = ['foo', ref('bar')]
10const queryKeyUnref = ['foo', 'bar']
11β
12const fn = () => 'mock'
13β
14describe('QueryCache', () => {
15 describe('isFetching', () => {
16 test('should properly unwrap 1 parameter', async () => {
17 const queryClient = new QueryClient()
18β
19 queryClient.isFetching({
20 queryKey: queryKeyRef,
21 })
22β
23 expect(QueryClientOrigin.prototype.isFetching).toBeCalledWith({
24 queryKey: queryKeyUnref,
25 })
26 })
27 })
28β
29 describe('isMutating', () => {
30 test('should properly unwrap 1 parameter', async () => {
31 const queryClient = new QueryClient()
32β
33 queryClient.isMutating({
34 mutationKey: queryKeyRef,
35 })
36β
37 expect(QueryClientOrigin.prototype.isMutating).toBeCalledWith({
38 mutationKey: queryKeyUnref,
39 })
40 })
41 })
42β
43 describe('getQueryData', () => {
44 test('should properly unwrap 1 parameter', async () => {
45 const queryClient = new QueryClient()
46β
47 queryClient.getQueryData(queryKeyRef)
48β
49 expect(QueryClientOrigin.prototype.getQueryData).toBeCalledWith(
50 queryKeyUnref,
51 )
52 })
53 })
54β
55 describe('getQueriesData', () => {
56 test('should properly unwrap queryKey param', async () => {
57 const queryClient = new QueryClient()
58β
59 queryClient.getQueriesData({ queryKey: queryKeyRef })
60β
61 expect(QueryClientOrigin.prototype.getQueriesData).toBeCalledWith({
62 queryKey: queryKeyUnref,
63 })
64 })
65β
66 test('should properly unwrap filters param', async () => {
67 const queryClient = new QueryClient()
68β
69 queryClient.getQueriesData({ queryKey: queryKeyRef })
70β
71 expect(QueryClientOrigin.prototype.getQueriesData).toBeCalledWith({
72 queryKey: queryKeyUnref,
73 })
74 })
75 })
76β
77 describe('setQueryData', () => {
78 test('should properly unwrap 3 parameter', async () => {
79 const queryClient = new QueryClient()
80β
81 queryClient.setQueryData(queryKeyRef, fn, {
82 updatedAt: ref(3),
83 })
84β
85 expect(QueryClientOrigin.prototype.setQueryData).toBeCalledWith(
86 queryKeyUnref,
87 fn,
88 { updatedAt: 3 },
89 )
90 })
91 })
92β
93 describe('setQueriesData', () => {
94 test('should properly unwrap params with queryKey', async () => {
95 const queryClient = new QueryClient()
96β
97 queryClient.setQueriesData({ queryKey: queryKeyRef }, fn, {
98 updatedAt: ref(3),
99 })
100β
101 expect(QueryClientOrigin.prototype.setQueriesData).toBeCalledWith(
102 { queryKey: queryKeyUnref },
103 fn,
104 { updatedAt: 3 },
105 )
106 })
107β
108 test('should properly unwrap params with filters', async () => {
109 const queryClient = new QueryClient()
110β
111 queryClient.setQueriesData({ queryKey: queryKeyRef }, fn, {
112 updatedAt: ref(3),
113 })
114β
115 expect(QueryClientOrigin.prototype.setQueriesData).toBeCalledWith(
116 { queryKey: queryKeyUnref },
117 fn,
118 { updatedAt: 3 },
119 )
120 })
121 })
122β
123 describe('getQueryState', () => {
124 test('should properly unwrap 1 parameter', async () => {
125 const queryClient = new QueryClient()
126β
127 queryClient.getQueryState(queryKeyRef)
128β
129 expect(QueryClientOrigin.prototype.getQueryState).toBeCalledWith(
130 queryKeyUnref,
131 )
132 })
133 })
134β
135 describe('removeQueries', () => {
136 test('should properly unwrap 1 parameter', async () => {
137 const queryClient = new QueryClient()
138β
139 queryClient.removeQueries({
140 queryKey: queryKeyRef,
141 })
142β
143 expect(QueryClientOrigin.prototype.removeQueries).toBeCalledWith({
144 queryKey: queryKeyUnref,
145 })
146 })
147 })
148β
149 describe('resetQueries', () => {
150 test('should properly unwrap 2 parameter', async () => {
151 const queryClient = new QueryClient()
152β
153 queryClient.resetQueries(
154 {
155 queryKey: queryKeyRef,
156 },
157 { cancelRefetch: ref(false) },
158 )
159β
160 expect(QueryClientOrigin.prototype.resetQueries).toBeCalledWith(
161 {
162 queryKey: queryKeyUnref,
163 },
164 { cancelRefetch: false },
165 )
166 })
167 })
168β
169 describe('cancelQueries', () => {
170 test('should properly unwrap 2 parameter', async () => {
171 const queryClient = new QueryClient()
172β
173 queryClient.cancelQueries(
174 {
175 queryKey: queryKeyRef,
176 },
177 { revert: ref(false) },
178 )
179β
180 expect(QueryClientOrigin.prototype.cancelQueries).toBeCalledWith(
181 {
182 queryKey: queryKeyUnref,
183 },
184 { revert: false },
185 )
186 })
187 })
188β
189 describe('invalidateQueries', () => {
190 test('should properly unwrap 2 parameter', async () => {
191 const queryClient = new QueryClient()
192β
193 queryClient.invalidateQueries(
194 {
195 queryKey: queryKeyRef,
196 },
197 { cancelRefetch: ref(false) },
198 )
199β
200 expect(QueryClientOrigin.prototype.invalidateQueries).toBeCalledWith(
201 {
202 queryKey: queryKeyUnref,
203 },
204 { cancelRefetch: false },
205 )
206 })
207 })
208β
209 describe('refetchQueries', () => {
210 test('should properly unwrap 2 parameter', async () => {
211 const queryClient = new QueryClient()
212β
213 queryClient.refetchQueries(
214 {
215 queryKey: queryKeyRef,
216 },
217 { cancelRefetch: ref(false) },
218 )
219β
220 expect(QueryClientOrigin.prototype.refetchQueries).toBeCalledWith(
221 {
222 queryKey: queryKeyUnref,
223 },
224 { cancelRefetch: false },
225 )
226 })
227 })
228β
229 describe('fetchQuery', () => {
230 test('should properly unwrap parameter', async () => {
231 const queryClient = new QueryClient()
232β
233 queryClient.fetchQuery({
234 queryKey: queryKeyRef,
235 })
236β
237 expect(QueryClientOrigin.prototype.fetchQuery).toBeCalledWith({
238 queryKey: queryKeyUnref,
239 })
240 })
241 })
242β
243 describe('prefetchQuery', () => {
244 test('should properly unwrap parameters', async () => {
245 const queryClient = new QueryClient()
246β
247 queryClient.prefetchQuery({ queryKey: queryKeyRef, queryFn: fn })
248β
249 expect(QueryClientOrigin.prototype.prefetchQuery).toBeCalledWith({
250 queryKey: queryKeyUnref,
251 queryFn: fn,
252 })
253 })
254 })
255β
256 describe('fetchInfiniteQuery', () => {
257 test('should properly unwrap parameter', async () => {
258 const queryClient = new QueryClient()
259β
260 queryClient.fetchInfiniteQuery({
261 queryKey: queryKeyRef,
262 initialPageParam: 0,
263 })
264β
265 expect(QueryClientOrigin.prototype.fetchInfiniteQuery).toBeCalledWith({
266 initialPageParam: 0,
267 queryKey: queryKeyUnref,
268 })
269 })
270 })
271β
272 describe('prefetchInfiniteQuery', () => {
273 test('should properly unwrap parameters', async () => {
274 const queryClient = new QueryClient()
275β
276 queryClient.prefetchInfiniteQuery({
277 queryKey: queryKeyRef,
278 queryFn: fn,
279 initialPageParam: 0,
280 })
281β
282 expect(QueryClientOrigin.prototype.prefetchInfiniteQuery).toBeCalledWith({
283 initialPageParam: 0,
284 queryKey: queryKeyUnref,
285 queryFn: fn,
286 })
287 })
288 })
289β
290 describe('setDefaultOptions', () => {
291 test('should properly unwrap parameters', async () => {
292 const queryClient = new QueryClient()
293β
294 queryClient.setDefaultOptions({
295 queries: {
296 enabled: ref(false),
297 },
298 })
299β
300 expect(QueryClientOrigin.prototype.setDefaultOptions).toBeCalledWith({
301 queries: {
302 enabled: false,
303 },
304 })
305 })
306 })
307β
308 describe('setQueryDefaults', () => {
309 test('should properly unwrap parameters', async () => {
310 const queryClient = new QueryClient()
311β
312 queryClient.setQueryDefaults(queryKeyRef, {
313 enabled: ref(false),
314 })
315β
316 expect(QueryClientOrigin.prototype.setQueryDefaults).toBeCalledWith(
317 queryKeyUnref,
318 {
319 enabled: false,
320 },
321 )
322 })
323 })
324β
325 describe('getQueryDefaults', () => {
326 test('should properly unwrap parameters', async () => {
327 const queryClient = new QueryClient()
328β
329 queryClient.getQueryDefaults(queryKeyRef)
330β
331 expect(QueryClientOrigin.prototype.getQueryDefaults).toBeCalledWith(
332 queryKeyUnref,
333 )
334 })
335 })
336β
337 describe('setMutationDefaults', () => {
338 test('should properly unwrap parameters', async () => {
339 const queryClient = new QueryClient()
340β
341 queryClient.setMutationDefaults(queryKeyRef, {
342 mutationKey: queryKeyRef,
343 })
344β
345 expect(QueryClientOrigin.prototype.setMutationDefaults).toBeCalledWith(
346 queryKeyUnref,
347 {
348 mutationKey: queryKeyUnref,
349 },
350 )
351 })
352 })
353β
354 describe('getMutationDefaults', () => {
355 test('should properly unwrap parameters', async () => {
356 const queryClient = new QueryClient()
357β
358 queryClient.getMutationDefaults(queryKeyRef)
359β
360 expect(QueryClientOrigin.prototype.getMutationDefaults).toBeCalledWith(
361 queryKeyUnref,
362 )
363 })
364 })
365})