@tanstack/solid-query 5.0.0-beta.9 → 5.0.0-rc.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/dev.cjs +176 -80
- package/build/dev.js +178 -82
- package/build/index.cjs +176 -80
- package/build/index.d.cts +9 -5
- package/build/index.d.ts +9 -5
- package/build/index.js +178 -82
- package/package.json +7 -3
- package/src/QueryClientProvider.tsx +14 -7
- package/src/__tests__/createInfiniteQuery.test.tsx +59 -52
- package/src/__tests__/createMutation.test.tsx +22 -4
- package/src/__tests__/createQueries.test.tsx +83 -87
- package/src/__tests__/createQuery.test.tsx +115 -201
- package/src/__tests__/suspense.test.tsx +35 -5
- package/src/__tests__/transition.test.tsx +1 -2
- package/src/__tests__/useIsFetching.test.tsx +2 -2
- package/src/__tests__/useIsMutating.test.tsx +3 -3
- package/src/__tests__/utils.tsx +1 -8
- package/src/createBaseQuery.ts +95 -61
- package/src/createMutation.ts +3 -3
- package/src/createQueries.ts +156 -52
- package/src/index.ts +1 -0
- package/src/isRestoring.ts +6 -0
- package/src/utils.ts +1 -1
|
@@ -33,7 +33,7 @@ import type {
|
|
|
33
33
|
import type { Mock } from 'vitest'
|
|
34
34
|
|
|
35
35
|
interface Result {
|
|
36
|
-
items: number
|
|
36
|
+
items: Array<number>
|
|
37
37
|
nextId?: number
|
|
38
38
|
prevId?: number
|
|
39
39
|
ts: number
|
|
@@ -62,14 +62,14 @@ describe('useInfiniteQuery', () => {
|
|
|
62
62
|
|
|
63
63
|
it('should return the correct states for a successful query', async () => {
|
|
64
64
|
const key = queryKey()
|
|
65
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
65
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
66
66
|
|
|
67
67
|
function Page() {
|
|
68
68
|
const state = createInfiniteQuery(() => ({
|
|
69
69
|
queryKey: key,
|
|
70
70
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
71
71
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
72
|
-
|
|
72
|
+
initialPageParam: 0,
|
|
73
73
|
}))
|
|
74
74
|
createRenderEffect(() => {
|
|
75
75
|
states.push({ ...state })
|
|
@@ -170,7 +170,7 @@ describe('useInfiniteQuery', () => {
|
|
|
170
170
|
|
|
171
171
|
retry: 1,
|
|
172
172
|
retryDelay: 10,
|
|
173
|
-
|
|
173
|
+
initialPageParam: start,
|
|
174
174
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
175
175
|
}))
|
|
176
176
|
|
|
@@ -199,8 +199,9 @@ describe('useInfiniteQuery', () => {
|
|
|
199
199
|
|
|
200
200
|
it('should keep the previous data when placeholderData is set', async () => {
|
|
201
201
|
const key = queryKey()
|
|
202
|
-
const states:
|
|
203
|
-
|
|
202
|
+
const states: Array<
|
|
203
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<string>>>
|
|
204
|
+
> = []
|
|
204
205
|
|
|
205
206
|
function Page() {
|
|
206
207
|
const [order, setOrder] = createSignal('desc')
|
|
@@ -213,7 +214,7 @@ describe('useInfiniteQuery', () => {
|
|
|
213
214
|
},
|
|
214
215
|
|
|
215
216
|
getNextPageParam: () => 1,
|
|
216
|
-
|
|
217
|
+
initialPageParam: 0,
|
|
217
218
|
placeholderData: keepPreviousData,
|
|
218
219
|
notifyOnChangeProps: 'all',
|
|
219
220
|
}))
|
|
@@ -304,7 +305,7 @@ describe('useInfiniteQuery', () => {
|
|
|
304
305
|
|
|
305
306
|
it('should be able to select a part of the data', async () => {
|
|
306
307
|
const key = queryKey()
|
|
307
|
-
const states: CreateInfiniteQueryResult<InfiniteData<string
|
|
308
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<string>>> = []
|
|
308
309
|
|
|
309
310
|
function Page() {
|
|
310
311
|
const state = createInfiniteQuery(() => ({
|
|
@@ -315,7 +316,7 @@ describe('useInfiniteQuery', () => {
|
|
|
315
316
|
pageParams: data.pageParams,
|
|
316
317
|
}),
|
|
317
318
|
getNextPageParam: () => undefined,
|
|
318
|
-
|
|
319
|
+
initialPageParam: 0,
|
|
319
320
|
}))
|
|
320
321
|
createRenderEffect(() => {
|
|
321
322
|
states.push({ ...state })
|
|
@@ -344,9 +345,9 @@ describe('useInfiniteQuery', () => {
|
|
|
344
345
|
|
|
345
346
|
it('should be able to select a new result and not cause infinite renders', async () => {
|
|
346
347
|
const key = queryKey()
|
|
347
|
-
const states:
|
|
348
|
-
InfiniteData<{ count: number; id: number }
|
|
349
|
-
>
|
|
348
|
+
const states: Array<
|
|
349
|
+
CreateInfiniteQueryResult<InfiniteData<{ count: number; id: number }>>
|
|
350
|
+
> = []
|
|
350
351
|
let selectCalled = 0
|
|
351
352
|
|
|
352
353
|
function Page() {
|
|
@@ -361,7 +362,7 @@ describe('useInfiniteQuery', () => {
|
|
|
361
362
|
}
|
|
362
363
|
},
|
|
363
364
|
getNextPageParam: () => undefined,
|
|
364
|
-
|
|
365
|
+
initialPageParam: 0,
|
|
365
366
|
}))
|
|
366
367
|
createRenderEffect(() => {
|
|
367
368
|
states.push({ ...state })
|
|
@@ -391,8 +392,9 @@ describe('useInfiniteQuery', () => {
|
|
|
391
392
|
|
|
392
393
|
it('should be able to reverse the data', async () => {
|
|
393
394
|
const key = queryKey()
|
|
394
|
-
const states:
|
|
395
|
-
|
|
395
|
+
const states: Array<
|
|
396
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
397
|
+
> = []
|
|
396
398
|
|
|
397
399
|
function Page() {
|
|
398
400
|
const state = createInfiniteQuery(() => ({
|
|
@@ -408,7 +410,7 @@ describe('useInfiniteQuery', () => {
|
|
|
408
410
|
}),
|
|
409
411
|
notifyOnChangeProps: 'all',
|
|
410
412
|
getNextPageParam: () => 1,
|
|
411
|
-
|
|
413
|
+
initialPageParam: 0,
|
|
412
414
|
}))
|
|
413
415
|
|
|
414
416
|
createRenderEffect(
|
|
@@ -466,8 +468,9 @@ describe('useInfiniteQuery', () => {
|
|
|
466
468
|
|
|
467
469
|
it('should be able to fetch a previous page', async () => {
|
|
468
470
|
const key = queryKey()
|
|
469
|
-
const states:
|
|
470
|
-
|
|
471
|
+
const states: Array<
|
|
472
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
473
|
+
> = []
|
|
471
474
|
|
|
472
475
|
function Page() {
|
|
473
476
|
const start = 10
|
|
@@ -479,7 +482,7 @@ describe('useInfiniteQuery', () => {
|
|
|
479
482
|
},
|
|
480
483
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
481
484
|
getPreviousPageParam: (firstPage) => firstPage - 1,
|
|
482
|
-
|
|
485
|
+
initialPageParam: start,
|
|
483
486
|
notifyOnChangeProps: 'all',
|
|
484
487
|
}))
|
|
485
488
|
|
|
@@ -554,8 +557,9 @@ describe('useInfiniteQuery', () => {
|
|
|
554
557
|
|
|
555
558
|
it('should be able to refetch when providing page params automatically', async () => {
|
|
556
559
|
const key = queryKey()
|
|
557
|
-
const states:
|
|
558
|
-
|
|
560
|
+
const states: Array<
|
|
561
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
562
|
+
> = []
|
|
559
563
|
|
|
560
564
|
function Page() {
|
|
561
565
|
const state = createInfiniteQuery(() => ({
|
|
@@ -567,7 +571,7 @@ describe('useInfiniteQuery', () => {
|
|
|
567
571
|
|
|
568
572
|
getPreviousPageParam: (firstPage) => firstPage - 1,
|
|
569
573
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
570
|
-
|
|
574
|
+
initialPageParam: 10,
|
|
571
575
|
notifyOnChangeProps: 'all',
|
|
572
576
|
}))
|
|
573
577
|
|
|
@@ -675,8 +679,9 @@ describe('useInfiniteQuery', () => {
|
|
|
675
679
|
|
|
676
680
|
it('should silently cancel any ongoing fetch when fetching more', async () => {
|
|
677
681
|
const key = queryKey()
|
|
678
|
-
const states:
|
|
679
|
-
|
|
682
|
+
const states: Array<
|
|
683
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
684
|
+
> = []
|
|
680
685
|
|
|
681
686
|
function Page() {
|
|
682
687
|
const start = 10
|
|
@@ -688,7 +693,7 @@ describe('useInfiniteQuery', () => {
|
|
|
688
693
|
},
|
|
689
694
|
|
|
690
695
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
691
|
-
|
|
696
|
+
initialPageParam: start,
|
|
692
697
|
notifyOnChangeProps: 'all',
|
|
693
698
|
}))
|
|
694
699
|
|
|
@@ -764,8 +769,8 @@ describe('useInfiniteQuery', () => {
|
|
|
764
769
|
it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => {
|
|
765
770
|
const key = queryKey()
|
|
766
771
|
const start = 10
|
|
767
|
-
const onAborts: Mock<any, any
|
|
768
|
-
const abortListeners: Mock<any, any
|
|
772
|
+
const onAborts: Array<Mock<any, any>> = []
|
|
773
|
+
const abortListeners: Array<Mock<any, any>> = []
|
|
769
774
|
const fetchPage = vi.fn<
|
|
770
775
|
[QueryFunctionContext<typeof key, number>],
|
|
771
776
|
Promise<number>
|
|
@@ -786,7 +791,7 @@ describe('useInfiniteQuery', () => {
|
|
|
786
791
|
queryKey: key,
|
|
787
792
|
queryFn: fetchPage,
|
|
788
793
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
789
|
-
|
|
794
|
+
initialPageParam: start,
|
|
790
795
|
}))
|
|
791
796
|
|
|
792
797
|
createEffect(() => {
|
|
@@ -846,8 +851,8 @@ describe('useInfiniteQuery', () => {
|
|
|
846
851
|
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
|
|
847
852
|
const key = queryKey()
|
|
848
853
|
const start = 10
|
|
849
|
-
const onAborts: Mock<any, any
|
|
850
|
-
const abortListeners: Mock<any, any
|
|
854
|
+
const onAborts: Array<Mock<any, any>> = []
|
|
855
|
+
const abortListeners: Array<Mock<any, any>> = []
|
|
851
856
|
const fetchPage = vi.fn<
|
|
852
857
|
[QueryFunctionContext<typeof key, number>],
|
|
853
858
|
Promise<number>
|
|
@@ -868,7 +873,7 @@ describe('useInfiniteQuery', () => {
|
|
|
868
873
|
queryKey: key,
|
|
869
874
|
queryFn: fetchPage,
|
|
870
875
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
871
|
-
|
|
876
|
+
initialPageParam: start,
|
|
872
877
|
}))
|
|
873
878
|
|
|
874
879
|
createEffect(() => {
|
|
@@ -918,7 +923,7 @@ describe('useInfiniteQuery', () => {
|
|
|
918
923
|
|
|
919
924
|
it('should keep fetching first page when not loaded yet and triggering fetch more', async () => {
|
|
920
925
|
const key = queryKey()
|
|
921
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
926
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
922
927
|
|
|
923
928
|
function Page() {
|
|
924
929
|
const start = 10
|
|
@@ -930,7 +935,7 @@ describe('useInfiniteQuery', () => {
|
|
|
930
935
|
},
|
|
931
936
|
|
|
932
937
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
933
|
-
|
|
938
|
+
initialPageParam: start,
|
|
934
939
|
notifyOnChangeProps: 'all',
|
|
935
940
|
}))
|
|
936
941
|
|
|
@@ -992,7 +997,7 @@ describe('useInfiniteQuery', () => {
|
|
|
992
997
|
getNextPageParam: (_, allPages) => {
|
|
993
998
|
return allPages.length === 4 ? undefined : allPages.length
|
|
994
999
|
},
|
|
995
|
-
|
|
1000
|
+
initialPageParam: 0,
|
|
996
1001
|
}))
|
|
997
1002
|
|
|
998
1003
|
return null
|
|
@@ -1028,8 +1033,9 @@ describe('useInfiniteQuery', () => {
|
|
|
1028
1033
|
|
|
1029
1034
|
it('should be able to set new pages with the query client', async () => {
|
|
1030
1035
|
const key = queryKey()
|
|
1031
|
-
const states:
|
|
1032
|
-
|
|
1036
|
+
const states: Array<
|
|
1037
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
1038
|
+
> = []
|
|
1033
1039
|
|
|
1034
1040
|
function Page() {
|
|
1035
1041
|
const [firstPage, setFirstPage] = createSignal(0)
|
|
@@ -1043,7 +1049,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1043
1049
|
|
|
1044
1050
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1045
1051
|
notifyOnChangeProps: 'all',
|
|
1046
|
-
|
|
1052
|
+
initialPageParam: firstPage(),
|
|
1047
1053
|
}))
|
|
1048
1054
|
|
|
1049
1055
|
createRenderEffect(() => {
|
|
@@ -1123,8 +1129,9 @@ describe('useInfiniteQuery', () => {
|
|
|
1123
1129
|
|
|
1124
1130
|
it('should only refetch the first page when initialData is provided', async () => {
|
|
1125
1131
|
const key = queryKey()
|
|
1126
|
-
const states:
|
|
1127
|
-
|
|
1132
|
+
const states: Array<
|
|
1133
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
1134
|
+
> = []
|
|
1128
1135
|
|
|
1129
1136
|
function Page() {
|
|
1130
1137
|
const state = createInfiniteQuery(() => ({
|
|
@@ -1136,7 +1143,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1136
1143
|
|
|
1137
1144
|
initialData: { pages: [1], pageParams: [1] },
|
|
1138
1145
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1139
|
-
|
|
1146
|
+
initialPageParam: 0,
|
|
1140
1147
|
notifyOnChangeProps: 'all',
|
|
1141
1148
|
}))
|
|
1142
1149
|
|
|
@@ -1201,13 +1208,13 @@ describe('useInfiniteQuery', () => {
|
|
|
1201
1208
|
|
|
1202
1209
|
it('should set hasNextPage to false if getNextPageParam returns undefined', async () => {
|
|
1203
1210
|
const key = queryKey()
|
|
1204
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
1211
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1205
1212
|
|
|
1206
1213
|
function Page() {
|
|
1207
1214
|
const state = createInfiniteQuery(() => ({
|
|
1208
1215
|
queryKey: key,
|
|
1209
1216
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
1210
|
-
|
|
1217
|
+
initialPageParam: 1,
|
|
1211
1218
|
getNextPageParam: () => undefined,
|
|
1212
1219
|
}))
|
|
1213
1220
|
|
|
@@ -1245,13 +1252,13 @@ describe('useInfiniteQuery', () => {
|
|
|
1245
1252
|
|
|
1246
1253
|
it('should compute hasNextPage correctly using initialData', async () => {
|
|
1247
1254
|
const key = queryKey()
|
|
1248
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
1255
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1249
1256
|
|
|
1250
1257
|
function Page() {
|
|
1251
1258
|
const state = createInfiniteQuery(() => ({
|
|
1252
1259
|
queryKey: key,
|
|
1253
1260
|
queryFn: ({ pageParam }): number => pageParam,
|
|
1254
|
-
|
|
1261
|
+
initialPageParam: 10,
|
|
1255
1262
|
initialData: { pages: [10], pageParams: [10] },
|
|
1256
1263
|
getNextPageParam: (lastPage) => (lastPage === 10 ? 11 : undefined),
|
|
1257
1264
|
}))
|
|
@@ -1289,13 +1296,13 @@ describe('useInfiniteQuery', () => {
|
|
|
1289
1296
|
|
|
1290
1297
|
it('should compute hasNextPage correctly for falsy getFetchMore return value using initialData', async () => {
|
|
1291
1298
|
const key = queryKey()
|
|
1292
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
1299
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1293
1300
|
|
|
1294
1301
|
function Page() {
|
|
1295
1302
|
const state = createInfiniteQuery(() => ({
|
|
1296
1303
|
queryKey: key,
|
|
1297
1304
|
queryFn: ({ pageParam }): number => pageParam,
|
|
1298
|
-
|
|
1305
|
+
initialPageParam: 10,
|
|
1299
1306
|
initialData: { pages: [10], pageParams: [10] },
|
|
1300
1307
|
getNextPageParam: () => undefined,
|
|
1301
1308
|
}))
|
|
@@ -1333,13 +1340,13 @@ describe('useInfiniteQuery', () => {
|
|
|
1333
1340
|
|
|
1334
1341
|
it('should not use selected data when computing hasNextPage', async () => {
|
|
1335
1342
|
const key = queryKey()
|
|
1336
|
-
const states: CreateInfiniteQueryResult<InfiniteData<string
|
|
1343
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<string>>> = []
|
|
1337
1344
|
|
|
1338
1345
|
function Page() {
|
|
1339
1346
|
const state = createInfiniteQuery(() => ({
|
|
1340
1347
|
queryKey: key,
|
|
1341
1348
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
1342
|
-
|
|
1349
|
+
initialPageParam: 1,
|
|
1343
1350
|
getNextPageParam: (lastPage) => (lastPage === 1 ? 2 : undefined),
|
|
1344
1351
|
select: (data) => ({
|
|
1345
1352
|
pages: data.pages.map((x) => x.toString()),
|
|
@@ -1402,7 +1409,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1402
1409
|
queryKey: key,
|
|
1403
1410
|
queryFn: ({ pageParam }) =>
|
|
1404
1411
|
fetchItemsWithLimit(pageParam, fetchCountRef++),
|
|
1405
|
-
|
|
1412
|
+
initialPageParam: 0,
|
|
1406
1413
|
getNextPageParam: (lastPage) => lastPage.nextId,
|
|
1407
1414
|
}))
|
|
1408
1415
|
|
|
@@ -1536,7 +1543,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1536
1543
|
fetchCountRef++,
|
|
1537
1544
|
pageParam === MAX || (pageParam === MAX - 1 && isRemovedLastPage()),
|
|
1538
1545
|
),
|
|
1539
|
-
|
|
1546
|
+
initialPageParam: 0,
|
|
1540
1547
|
getNextPageParam: (lastPage) => lastPage.nextId,
|
|
1541
1548
|
}))
|
|
1542
1549
|
|
|
@@ -1670,7 +1677,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1670
1677
|
queryKey: key,
|
|
1671
1678
|
queryFn,
|
|
1672
1679
|
getNextPageParam: () => undefined,
|
|
1673
|
-
|
|
1680
|
+
initialPageParam: 0,
|
|
1674
1681
|
}))
|
|
1675
1682
|
return (
|
|
1676
1683
|
<div>
|
|
@@ -1704,7 +1711,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1704
1711
|
queryKey: key,
|
|
1705
1712
|
queryFn,
|
|
1706
1713
|
getNextPageParam: () => undefined,
|
|
1707
|
-
|
|
1714
|
+
initialPageParam: 0,
|
|
1708
1715
|
}),
|
|
1709
1716
|
() => queryClient,
|
|
1710
1717
|
)
|
|
@@ -64,6 +64,10 @@ describe('createMutation', () => {
|
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
it('should be able to reset `error`', async () => {
|
|
67
|
+
const consoleMock = vi
|
|
68
|
+
.spyOn(console, 'error')
|
|
69
|
+
.mockImplementation(() => undefined)
|
|
70
|
+
|
|
67
71
|
function Page() {
|
|
68
72
|
const mutation = createMutation<string, Error>(() => ({
|
|
69
73
|
mutationFn: () => {
|
|
@@ -105,6 +109,8 @@ describe('createMutation', () => {
|
|
|
105
109
|
await waitFor(() => {
|
|
106
110
|
expect(screen.queryByRole('heading')).toBeNull()
|
|
107
111
|
})
|
|
112
|
+
|
|
113
|
+
consoleMock.mockRestore()
|
|
108
114
|
})
|
|
109
115
|
|
|
110
116
|
it('should be able to call `onSuccess` and `onSettled` after each successful mutate', async () => {
|
|
@@ -312,7 +318,7 @@ describe('createMutation', () => {
|
|
|
312
318
|
})
|
|
313
319
|
|
|
314
320
|
it('should be able to override the useMutation success callbacks', async () => {
|
|
315
|
-
const callbacks: string
|
|
321
|
+
const callbacks: Array<string> = []
|
|
316
322
|
|
|
317
323
|
function Page() {
|
|
318
324
|
const mutation = createMutation(() => ({
|
|
@@ -363,7 +369,7 @@ describe('createMutation', () => {
|
|
|
363
369
|
})
|
|
364
370
|
|
|
365
371
|
it('should be able to override the error callbacks when using mutateAsync', async () => {
|
|
366
|
-
const callbacks: string
|
|
372
|
+
const callbacks: Array<string> = []
|
|
367
373
|
|
|
368
374
|
function Page() {
|
|
369
375
|
const mutation = createMutation(() => ({
|
|
@@ -425,7 +431,7 @@ describe('createMutation', () => {
|
|
|
425
431
|
},
|
|
426
432
|
})
|
|
427
433
|
|
|
428
|
-
const states: CreateMutationResult<any, any, any, any
|
|
434
|
+
const states: Array<CreateMutationResult<any, any, any, any>> = []
|
|
429
435
|
|
|
430
436
|
function Page() {
|
|
431
437
|
const mutation = createMutation<string, unknown, string>(() => ({
|
|
@@ -670,7 +676,7 @@ describe('createMutation', () => {
|
|
|
670
676
|
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
671
677
|
|
|
672
678
|
let count = 0
|
|
673
|
-
const states: CreateMutationResult<any, any, any, any
|
|
679
|
+
const states: Array<CreateMutationResult<any, any, any, any>> = []
|
|
674
680
|
|
|
675
681
|
function Page() {
|
|
676
682
|
const mutation = createMutation(() => ({
|
|
@@ -781,6 +787,10 @@ describe('createMutation', () => {
|
|
|
781
787
|
})
|
|
782
788
|
|
|
783
789
|
it('should be able to throw an error when throwOnError is set to true', async () => {
|
|
790
|
+
const consoleMock = vi
|
|
791
|
+
.spyOn(console, 'error')
|
|
792
|
+
.mockImplementation(() => undefined)
|
|
793
|
+
|
|
784
794
|
function Page() {
|
|
785
795
|
const mutation = createMutation<string, Error>(() => ({
|
|
786
796
|
mutationFn: () => {
|
|
@@ -817,9 +827,15 @@ describe('createMutation', () => {
|
|
|
817
827
|
await waitFor(() => {
|
|
818
828
|
expect(screen.queryByText('error')).not.toBeNull()
|
|
819
829
|
})
|
|
830
|
+
|
|
831
|
+
consoleMock.mockRestore()
|
|
820
832
|
})
|
|
821
833
|
|
|
822
834
|
it('should be able to throw an error when throwOnError is a function that returns true', async () => {
|
|
835
|
+
const consoleMock = vi
|
|
836
|
+
.spyOn(console, 'error')
|
|
837
|
+
.mockImplementation(() => undefined)
|
|
838
|
+
|
|
823
839
|
let boundary = false
|
|
824
840
|
function Page() {
|
|
825
841
|
const mutation = createMutation<string, Error>(() => ({
|
|
@@ -867,6 +883,8 @@ describe('createMutation', () => {
|
|
|
867
883
|
await waitFor(() => {
|
|
868
884
|
expect(screen.queryByText('error boundary')).not.toBeNull()
|
|
869
885
|
})
|
|
886
|
+
|
|
887
|
+
consoleMock.mockRestore()
|
|
870
888
|
})
|
|
871
889
|
|
|
872
890
|
it('should pass meta to mutation', async () => {
|