@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
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
import {
|
|
22
22
|
Blink,
|
|
23
23
|
createQueryClient,
|
|
24
|
-
expectType,
|
|
25
24
|
mockOnlineManagerIsOnline,
|
|
26
25
|
mockVisibilityState,
|
|
27
26
|
queryKey,
|
|
@@ -49,32 +48,32 @@ describe('createQuery', () => {
|
|
|
49
48
|
function Page() {
|
|
50
49
|
// unspecified query function should default to unknown
|
|
51
50
|
const noQueryFn = createQuery(() => ({ queryKey: key }))
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
expectTypeOf<unknown>(noQueryFn.data)
|
|
52
|
+
expectTypeOf<unknown>(noQueryFn.error)
|
|
54
53
|
|
|
55
54
|
// it should infer the result type from the query function
|
|
56
55
|
const fromQueryFn = createQuery(() => ({
|
|
57
56
|
queryKey: key,
|
|
58
57
|
queryFn: () => 'test',
|
|
59
58
|
}))
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
expectTypeOf<string | undefined>(fromQueryFn.data)
|
|
60
|
+
expectTypeOf<unknown>(fromQueryFn.error)
|
|
62
61
|
|
|
63
62
|
// it should be possible to specify the result type
|
|
64
63
|
const withResult = createQuery<string>(() => ({
|
|
65
64
|
queryKey: key,
|
|
66
65
|
queryFn: () => 'test',
|
|
67
66
|
}))
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
expectTypeOf<string | undefined>(withResult.data)
|
|
68
|
+
expectTypeOf<unknown | null>(withResult.error)
|
|
70
69
|
|
|
71
70
|
// it should be possible to specify the error type
|
|
72
71
|
const withError = createQuery<string, Error>(() => ({
|
|
73
72
|
queryKey: key,
|
|
74
73
|
queryFn: () => 'test',
|
|
75
74
|
}))
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
expectTypeOf<string | undefined>(withError.data)
|
|
76
|
+
expectTypeOf<Error | null>(withError.error)
|
|
78
77
|
|
|
79
78
|
// it should provide the result type in the configuration
|
|
80
79
|
createQuery(() => ({
|
|
@@ -87,12 +86,12 @@ describe('createQuery', () => {
|
|
|
87
86
|
queryKey: key,
|
|
88
87
|
queryFn: () => (Math.random() > 0.5 ? 'a' : 'b'),
|
|
89
88
|
}))
|
|
90
|
-
|
|
89
|
+
expectTypeOf<'a' | 'b' | undefined>(unionTypeSync.data)
|
|
91
90
|
const unionTypeAsync = createQuery<'a' | 'b'>(() => ({
|
|
92
91
|
queryKey: key,
|
|
93
92
|
queryFn: () => Promise.resolve(Math.random() > 0.5 ? 'a' : 'b'),
|
|
94
93
|
}))
|
|
95
|
-
|
|
94
|
+
expectTypeOf<'a' | 'b' | undefined>(unionTypeAsync.data)
|
|
96
95
|
|
|
97
96
|
// should error when the query function result does not match with the specified type
|
|
98
97
|
// @ts-expect-error
|
|
@@ -107,15 +106,15 @@ describe('createQuery', () => {
|
|
|
107
106
|
queryKey: key,
|
|
108
107
|
queryFn: () => queryFn(),
|
|
109
108
|
}))
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
expectTypeOf<string | undefined>(fromGenericQueryFn.data)
|
|
110
|
+
expectTypeOf<unknown>(fromGenericQueryFn.error)
|
|
112
111
|
|
|
113
112
|
const fromGenericOptionsQueryFn = createQuery(() => ({
|
|
114
113
|
queryKey: key,
|
|
115
114
|
queryFn: () => queryFn(),
|
|
116
115
|
}))
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
expectTypeOf<string | undefined>(fromGenericOptionsQueryFn.data)
|
|
117
|
+
expectTypeOf<unknown>(fromGenericOptionsQueryFn.error)
|
|
119
118
|
|
|
120
119
|
type MyData = number
|
|
121
120
|
type MyQueryKey = readonly ['my-data', number]
|
|
@@ -134,7 +133,7 @@ describe('createQuery', () => {
|
|
|
134
133
|
const getMyDataStringKey: QueryFunction<MyData, ['1']> = async (
|
|
135
134
|
context,
|
|
136
135
|
) => {
|
|
137
|
-
|
|
136
|
+
expectTypeOf<['1']>(context.queryKey)
|
|
138
137
|
return Number(context.queryKey[0]) + 42
|
|
139
138
|
}
|
|
140
139
|
|
|
@@ -173,7 +172,7 @@ describe('createQuery', () => {
|
|
|
173
172
|
...options,
|
|
174
173
|
}))
|
|
175
174
|
const test = useWrappedQuery([''], async () => '1')
|
|
176
|
-
|
|
175
|
+
expectTypeOf<string | undefined>(test.data)
|
|
177
176
|
|
|
178
177
|
// handles wrapped queries with custom fetcher passed directly to createQuery
|
|
179
178
|
const useWrappedFuncStyleQuery = <
|
|
@@ -190,7 +189,7 @@ describe('createQuery', () => {
|
|
|
190
189
|
>,
|
|
191
190
|
) => createQuery(() => ({ queryKey: qk, queryFn: fetcher, ...options }))
|
|
192
191
|
const testFuncStyle = useWrappedFuncStyleQuery([''], async () => true)
|
|
193
|
-
|
|
192
|
+
expectTypeOf<boolean | undefined>(testFuncStyle.data)
|
|
194
193
|
}
|
|
195
194
|
})
|
|
196
195
|
|
|
@@ -227,7 +226,7 @@ describe('createQuery', () => {
|
|
|
227
226
|
|
|
228
227
|
it('should return the correct states for a successful query', async () => {
|
|
229
228
|
const key = queryKey()
|
|
230
|
-
const states: CreateQueryResult<string
|
|
229
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
231
230
|
|
|
232
231
|
function Page(): JSX.Element {
|
|
233
232
|
const state = createQuery<string, Error>(() => ({
|
|
@@ -243,14 +242,14 @@ describe('createQuery', () => {
|
|
|
243
242
|
})
|
|
244
243
|
|
|
245
244
|
if (state.isPending) {
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
expectTypeOf<undefined>(state.data)
|
|
246
|
+
expectTypeOf<null>(state.error)
|
|
248
247
|
} else if (state.isLoadingError) {
|
|
249
|
-
|
|
250
|
-
|
|
248
|
+
expectTypeOf<undefined>(state.data)
|
|
249
|
+
expectTypeOf<Error>(state.error)
|
|
251
250
|
} else {
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
expectTypeOf<string>(state.data)
|
|
252
|
+
expectTypeOf<Error | null>(state.error)
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
return (
|
|
@@ -333,7 +332,7 @@ describe('createQuery', () => {
|
|
|
333
332
|
it('should return the correct states for an unsuccessful query', async () => {
|
|
334
333
|
const key = queryKey()
|
|
335
334
|
|
|
336
|
-
const states: CreateQueryResult<unknown, Error
|
|
335
|
+
const states: Array<CreateQueryResult<unknown, Error>> = []
|
|
337
336
|
|
|
338
337
|
function Page() {
|
|
339
338
|
const state = createQuery(() => ({
|
|
@@ -448,7 +447,7 @@ describe('createQuery', () => {
|
|
|
448
447
|
|
|
449
448
|
it('should set isFetchedAfterMount to true after a query has been fetched', async () => {
|
|
450
449
|
const key = queryKey()
|
|
451
|
-
const states: CreateQueryResult<string
|
|
450
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
452
451
|
|
|
453
452
|
await queryClient.prefetchQuery({
|
|
454
453
|
queryKey: key,
|
|
@@ -605,7 +604,7 @@ describe('createQuery', () => {
|
|
|
605
604
|
|
|
606
605
|
it('should be able to watch a query without providing a query function', async () => {
|
|
607
606
|
const key = queryKey()
|
|
608
|
-
const states: CreateQueryResult<string
|
|
607
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
609
608
|
|
|
610
609
|
queryClient.setQueryDefaults(key, { queryFn: () => 'data' })
|
|
611
610
|
|
|
@@ -632,7 +631,7 @@ describe('createQuery', () => {
|
|
|
632
631
|
|
|
633
632
|
it('should pick up a query when re-mounting with gcTime 0', async () => {
|
|
634
633
|
const key = queryKey()
|
|
635
|
-
const states: CreateQueryResult<string
|
|
634
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
636
635
|
|
|
637
636
|
function Page() {
|
|
638
637
|
const [toggle, setToggle] = createSignal(false)
|
|
@@ -712,7 +711,7 @@ describe('createQuery', () => {
|
|
|
712
711
|
|
|
713
712
|
it('should fetch when refetchOnMount is false and nothing has been fetched yet', async () => {
|
|
714
713
|
const key = queryKey()
|
|
715
|
-
const states: CreateQueryResult<string
|
|
714
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
716
715
|
|
|
717
716
|
function Page() {
|
|
718
717
|
const state = createQuery(() => ({
|
|
@@ -741,7 +740,7 @@ describe('createQuery', () => {
|
|
|
741
740
|
|
|
742
741
|
it('should not fetch when refetchOnMount is false and data has been fetched already', async () => {
|
|
743
742
|
const key = queryKey()
|
|
744
|
-
const states: CreateQueryResult<string
|
|
743
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
745
744
|
|
|
746
745
|
queryClient.setQueryData(key, 'prefetched')
|
|
747
746
|
|
|
@@ -771,7 +770,7 @@ describe('createQuery', () => {
|
|
|
771
770
|
|
|
772
771
|
it('should be able to select a part of the data with select', async () => {
|
|
773
772
|
const key = queryKey()
|
|
774
|
-
const states: CreateQueryResult<string
|
|
773
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
775
774
|
|
|
776
775
|
function Page() {
|
|
777
776
|
const state = createQuery(() => ({
|
|
@@ -800,7 +799,7 @@ describe('createQuery', () => {
|
|
|
800
799
|
|
|
801
800
|
it('should be able to select a part of the data with select in object syntax', async () => {
|
|
802
801
|
const key = queryKey()
|
|
803
|
-
const states: CreateQueryResult<string
|
|
802
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
804
803
|
|
|
805
804
|
function Page() {
|
|
806
805
|
const state = createQuery(() => ({
|
|
@@ -829,7 +828,7 @@ describe('createQuery', () => {
|
|
|
829
828
|
|
|
830
829
|
it('should be able to select a part of the data with select in object syntax', async () => {
|
|
831
830
|
const key = queryKey()
|
|
832
|
-
const states: CreateQueryResult<string
|
|
831
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
833
832
|
|
|
834
833
|
function Page() {
|
|
835
834
|
const state = createQuery(() => ({
|
|
@@ -858,7 +857,7 @@ describe('createQuery', () => {
|
|
|
858
857
|
|
|
859
858
|
it('should not re-render when it should only re-render only data change and the selected data did not change', async () => {
|
|
860
859
|
const key = queryKey()
|
|
861
|
-
const states: CreateQueryResult<string
|
|
860
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
862
861
|
|
|
863
862
|
function Page() {
|
|
864
863
|
const state = createQuery(() => ({
|
|
@@ -898,7 +897,7 @@ describe('createQuery', () => {
|
|
|
898
897
|
|
|
899
898
|
it('should throw an error when a selector throws', async () => {
|
|
900
899
|
const key = queryKey()
|
|
901
|
-
const states:
|
|
900
|
+
const states: Array<{ status: string; data?: unknown; error?: Error }> = []
|
|
902
901
|
const error = new Error('Select Error')
|
|
903
902
|
|
|
904
903
|
function Page() {
|
|
@@ -910,7 +909,10 @@ describe('createQuery', () => {
|
|
|
910
909
|
},
|
|
911
910
|
}))
|
|
912
911
|
createRenderEffect(() => {
|
|
913
|
-
|
|
912
|
+
if (state.status === 'pending')
|
|
913
|
+
states.push({ status: 'pending', data: undefined })
|
|
914
|
+
else if (state.status === 'error')
|
|
915
|
+
states.push({ status: 'error', error: state.error })
|
|
914
916
|
})
|
|
915
917
|
return null
|
|
916
918
|
}
|
|
@@ -931,7 +933,7 @@ describe('createQuery', () => {
|
|
|
931
933
|
|
|
932
934
|
it('should track properties and only re-render when a tracked property changes', async () => {
|
|
933
935
|
const key = queryKey()
|
|
934
|
-
const states: CreateQueryResult<string
|
|
936
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
935
937
|
|
|
936
938
|
function Page() {
|
|
937
939
|
const state = createQuery(() => ({
|
|
@@ -979,7 +981,7 @@ describe('createQuery', () => {
|
|
|
979
981
|
it('should always re-render if we are tracking props but not using any', async () => {
|
|
980
982
|
const key = queryKey()
|
|
981
983
|
let renderCount = 0
|
|
982
|
-
const states: CreateQueryResult<string
|
|
984
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
983
985
|
|
|
984
986
|
function Page() {
|
|
985
987
|
const state = createQuery(() => ({
|
|
@@ -1032,7 +1034,7 @@ describe('createQuery', () => {
|
|
|
1032
1034
|
{ id: '2', done: true },
|
|
1033
1035
|
]
|
|
1034
1036
|
|
|
1035
|
-
const states: CreateQueryResult<typeof result1
|
|
1037
|
+
const states: Array<CreateQueryResult<typeof result1>> = []
|
|
1036
1038
|
|
|
1037
1039
|
let count = 0
|
|
1038
1040
|
|
|
@@ -1091,7 +1093,7 @@ describe('createQuery', () => {
|
|
|
1091
1093
|
|
|
1092
1094
|
it('should use query function from hook when the existing query does not have a query function', async () => {
|
|
1093
1095
|
const key = queryKey()
|
|
1094
|
-
const results: CreateQueryResult<string
|
|
1096
|
+
const results: Array<CreateQueryResult<string>> = []
|
|
1095
1097
|
|
|
1096
1098
|
queryClient.setQueryData(key, 'set')
|
|
1097
1099
|
|
|
@@ -1140,7 +1142,7 @@ describe('createQuery', () => {
|
|
|
1140
1142
|
|
|
1141
1143
|
it('should update query stale state and refetch when invalidated with invalidateQueries', async () => {
|
|
1142
1144
|
const key = queryKey()
|
|
1143
|
-
const states: CreateQueryResult<number
|
|
1145
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1144
1146
|
let count = 0
|
|
1145
1147
|
|
|
1146
1148
|
function Page() {
|
|
@@ -1214,7 +1216,7 @@ describe('createQuery', () => {
|
|
|
1214
1216
|
|
|
1215
1217
|
it('should not update disabled query when refetched with refetchQueries', async () => {
|
|
1216
1218
|
const key = queryKey()
|
|
1217
|
-
const states: CreateQueryResult<number
|
|
1219
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1218
1220
|
let count = 0
|
|
1219
1221
|
|
|
1220
1222
|
function Page() {
|
|
@@ -1260,7 +1262,7 @@ describe('createQuery', () => {
|
|
|
1260
1262
|
|
|
1261
1263
|
it('should not refetch disabled query when invalidated with invalidateQueries', async () => {
|
|
1262
1264
|
const key = queryKey()
|
|
1263
|
-
const states: CreateQueryResult<number
|
|
1265
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1264
1266
|
let count = 0
|
|
1265
1267
|
|
|
1266
1268
|
function Page() {
|
|
@@ -1306,7 +1308,7 @@ describe('createQuery', () => {
|
|
|
1306
1308
|
|
|
1307
1309
|
it('should not fetch when switching to a disabled query', async () => {
|
|
1308
1310
|
const key = queryKey()
|
|
1309
|
-
const states: CreateQueryResult<number
|
|
1311
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1310
1312
|
|
|
1311
1313
|
function Page() {
|
|
1312
1314
|
const [count, setCount] = createSignal(0)
|
|
@@ -1363,7 +1365,7 @@ describe('createQuery', () => {
|
|
|
1363
1365
|
|
|
1364
1366
|
it('should keep the previous data when placeholderData is set', async () => {
|
|
1365
1367
|
const key = queryKey()
|
|
1366
|
-
const states: CreateQueryResult<number
|
|
1368
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1367
1369
|
|
|
1368
1370
|
function Page() {
|
|
1369
1371
|
const [count, setCount] = createSignal(0)
|
|
@@ -1430,7 +1432,7 @@ describe('createQuery', () => {
|
|
|
1430
1432
|
|
|
1431
1433
|
it('should not show initial data from next query if placeholderData is set', async () => {
|
|
1432
1434
|
const key = queryKey()
|
|
1433
|
-
const states: DefinedCreateQueryResult<number
|
|
1435
|
+
const states: Array<DefinedCreateQueryResult<number>> = []
|
|
1434
1436
|
|
|
1435
1437
|
function Page() {
|
|
1436
1438
|
const [count, setCount] = createSignal(0)
|
|
@@ -1508,101 +1510,9 @@ describe('createQuery', () => {
|
|
|
1508
1510
|
})
|
|
1509
1511
|
})
|
|
1510
1512
|
|
|
1511
|
-
it('should keep the previous data on disabled query when placeholderData is set to identity function', async () => {
|
|
1512
|
-
const key = queryKey()
|
|
1513
|
-
const states: CreateQueryResult<number>[] = []
|
|
1514
|
-
|
|
1515
|
-
function Page() {
|
|
1516
|
-
const [count, setCount] = createSignal(0)
|
|
1517
|
-
|
|
1518
|
-
const state = createQuery(() => ({
|
|
1519
|
-
queryKey: [key, count()],
|
|
1520
|
-
queryFn: async () => {
|
|
1521
|
-
await sleep(10)
|
|
1522
|
-
return count()
|
|
1523
|
-
},
|
|
1524
|
-
enabled: false,
|
|
1525
|
-
placeholderData: keepPreviousData,
|
|
1526
|
-
notifyOnChangeProps: 'all',
|
|
1527
|
-
}))
|
|
1528
|
-
|
|
1529
|
-
createRenderEffect(() => {
|
|
1530
|
-
states.push({ ...state })
|
|
1531
|
-
})
|
|
1532
|
-
|
|
1533
|
-
createEffect(() => {
|
|
1534
|
-
const refetch = state.refetch
|
|
1535
|
-
refetch()
|
|
1536
|
-
|
|
1537
|
-
setActTimeout(() => {
|
|
1538
|
-
setCount(1)
|
|
1539
|
-
}, 20)
|
|
1540
|
-
|
|
1541
|
-
setActTimeout(() => {
|
|
1542
|
-
refetch()
|
|
1543
|
-
}, 30)
|
|
1544
|
-
})
|
|
1545
|
-
|
|
1546
|
-
return null
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
render(() => (
|
|
1550
|
-
<QueryClientProvider client={queryClient}>
|
|
1551
|
-
<Page />
|
|
1552
|
-
</QueryClientProvider>
|
|
1553
|
-
))
|
|
1554
|
-
|
|
1555
|
-
await sleep(100)
|
|
1556
|
-
|
|
1557
|
-
expect(states.length).toBe(6)
|
|
1558
|
-
|
|
1559
|
-
// Disabled query
|
|
1560
|
-
expect(states[0]).toMatchObject({
|
|
1561
|
-
data: undefined,
|
|
1562
|
-
isFetching: false,
|
|
1563
|
-
isSuccess: false,
|
|
1564
|
-
isPlaceholderData: false,
|
|
1565
|
-
})
|
|
1566
|
-
// Fetching query
|
|
1567
|
-
expect(states[1]).toMatchObject({
|
|
1568
|
-
data: undefined,
|
|
1569
|
-
isFetching: true,
|
|
1570
|
-
isSuccess: false,
|
|
1571
|
-
isPlaceholderData: false,
|
|
1572
|
-
})
|
|
1573
|
-
// Fetched query
|
|
1574
|
-
expect(states[2]).toMatchObject({
|
|
1575
|
-
data: 0,
|
|
1576
|
-
isFetching: false,
|
|
1577
|
-
isSuccess: true,
|
|
1578
|
-
isPlaceholderData: false,
|
|
1579
|
-
})
|
|
1580
|
-
// Set state
|
|
1581
|
-
expect(states[3]).toMatchObject({
|
|
1582
|
-
data: 0,
|
|
1583
|
-
isFetching: false,
|
|
1584
|
-
isSuccess: true,
|
|
1585
|
-
isPlaceholderData: true,
|
|
1586
|
-
})
|
|
1587
|
-
// Fetching new query
|
|
1588
|
-
expect(states[4]).toMatchObject({
|
|
1589
|
-
data: 0,
|
|
1590
|
-
isFetching: true,
|
|
1591
|
-
isSuccess: true,
|
|
1592
|
-
isPlaceholderData: true,
|
|
1593
|
-
})
|
|
1594
|
-
// Fetched new query
|
|
1595
|
-
expect(states[5]).toMatchObject({
|
|
1596
|
-
data: 1,
|
|
1597
|
-
isFetching: false,
|
|
1598
|
-
isSuccess: true,
|
|
1599
|
-
isPlaceholderData: false,
|
|
1600
|
-
})
|
|
1601
|
-
})
|
|
1602
|
-
|
|
1603
1513
|
it('should keep the previous data on disabled query when placeholderData is set and switching query key multiple times', async () => {
|
|
1604
1514
|
const key = queryKey()
|
|
1605
|
-
const states: CreateQueryResult<number
|
|
1515
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1606
1516
|
|
|
1607
1517
|
queryClient.setQueryData([key, 10], 10)
|
|
1608
1518
|
|
|
@@ -1684,7 +1594,7 @@ describe('createQuery', () => {
|
|
|
1684
1594
|
|
|
1685
1595
|
it('should use the correct query function when components use different configurations', async () => {
|
|
1686
1596
|
const key = queryKey()
|
|
1687
|
-
const states: CreateQueryResult<number
|
|
1597
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1688
1598
|
|
|
1689
1599
|
function FirstComponent() {
|
|
1690
1600
|
const state = createQuery(() => ({
|
|
@@ -1752,8 +1662,8 @@ describe('createQuery', () => {
|
|
|
1752
1662
|
|
|
1753
1663
|
it('should be able to set different stale times for a query', async () => {
|
|
1754
1664
|
const key = queryKey()
|
|
1755
|
-
const states1: CreateQueryResult<string
|
|
1756
|
-
const states2: CreateQueryResult<string
|
|
1665
|
+
const states1: Array<CreateQueryResult<string>> = []
|
|
1666
|
+
const states2: Array<CreateQueryResult<string>> = []
|
|
1757
1667
|
|
|
1758
1668
|
await queryClient.prefetchQuery({
|
|
1759
1669
|
queryKey: key,
|
|
@@ -1859,7 +1769,7 @@ describe('createQuery', () => {
|
|
|
1859
1769
|
|
|
1860
1770
|
it('should re-render when a query becomes stale', async () => {
|
|
1861
1771
|
const key = queryKey()
|
|
1862
|
-
const states: CreateQueryResult<string
|
|
1772
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
1863
1773
|
|
|
1864
1774
|
function Page() {
|
|
1865
1775
|
const state = createQuery(() => ({
|
|
@@ -1889,7 +1799,7 @@ describe('createQuery', () => {
|
|
|
1889
1799
|
|
|
1890
1800
|
it('should not re-render when it should only re-render on data changes and the data did not change', async () => {
|
|
1891
1801
|
const key = queryKey()
|
|
1892
|
-
const states: CreateQueryResult<string
|
|
1802
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
1893
1803
|
|
|
1894
1804
|
function Page() {
|
|
1895
1805
|
const state = createQuery(() => ({
|
|
@@ -2131,7 +2041,7 @@ describe('createQuery', () => {
|
|
|
2131
2041
|
|
|
2132
2042
|
it('should not refetch query on focus when `enabled` is set to `false`', async () => {
|
|
2133
2043
|
const key = queryKey()
|
|
2134
|
-
const queryFn = vi.fn<unknown
|
|
2044
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
2135
2045
|
|
|
2136
2046
|
function Page() {
|
|
2137
2047
|
const { data = 'default' } = createQuery(() => ({
|
|
@@ -2162,7 +2072,7 @@ describe('createQuery', () => {
|
|
|
2162
2072
|
|
|
2163
2073
|
it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to `false`', async () => {
|
|
2164
2074
|
const key = queryKey()
|
|
2165
|
-
const states: CreateQueryResult<number
|
|
2075
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2166
2076
|
let count = 0
|
|
2167
2077
|
|
|
2168
2078
|
function Page() {
|
|
@@ -2197,7 +2107,7 @@ describe('createQuery', () => {
|
|
|
2197
2107
|
|
|
2198
2108
|
it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to a function that returns `false`', async () => {
|
|
2199
2109
|
const key = queryKey()
|
|
2200
|
-
const states: CreateQueryResult<number
|
|
2110
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2201
2111
|
let count = 0
|
|
2202
2112
|
|
|
2203
2113
|
function Page() {
|
|
@@ -2232,7 +2142,7 @@ describe('createQuery', () => {
|
|
|
2232
2142
|
|
|
2233
2143
|
it('should not refetch fresh query on focus when `refetchOnWindowFocus` is set to `true`', async () => {
|
|
2234
2144
|
const key = queryKey()
|
|
2235
|
-
const states: CreateQueryResult<number
|
|
2145
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2236
2146
|
let count = 0
|
|
2237
2147
|
|
|
2238
2148
|
function Page() {
|
|
@@ -2267,7 +2177,7 @@ describe('createQuery', () => {
|
|
|
2267
2177
|
|
|
2268
2178
|
it('should refetch fresh query on focus when `refetchOnWindowFocus` is set to `always`', async () => {
|
|
2269
2179
|
const key = queryKey()
|
|
2270
|
-
const states: CreateQueryResult<number
|
|
2180
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2271
2181
|
let count = 0
|
|
2272
2182
|
|
|
2273
2183
|
function Page() {
|
|
@@ -2307,7 +2217,7 @@ describe('createQuery', () => {
|
|
|
2307
2217
|
|
|
2308
2218
|
it('should calculate focus behaviour for refetchOnWindowFocus depending on function', async () => {
|
|
2309
2219
|
const key = queryKey()
|
|
2310
|
-
const states: CreateQueryResult<number
|
|
2220
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2311
2221
|
let count = 0
|
|
2312
2222
|
|
|
2313
2223
|
function Page() {
|
|
@@ -2357,7 +2267,7 @@ describe('createQuery', () => {
|
|
|
2357
2267
|
|
|
2358
2268
|
it('should refetch fresh query when refetchOnMount is set to always', async () => {
|
|
2359
2269
|
const key = queryKey()
|
|
2360
|
-
const states: CreateQueryResult<string
|
|
2270
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2361
2271
|
|
|
2362
2272
|
await queryClient.prefetchQuery({
|
|
2363
2273
|
queryKey: key,
|
|
@@ -2400,7 +2310,7 @@ describe('createQuery', () => {
|
|
|
2400
2310
|
|
|
2401
2311
|
it('should refetch stale query when refetchOnMount is set to true', async () => {
|
|
2402
2312
|
const key = queryKey()
|
|
2403
|
-
const states: CreateQueryResult<string
|
|
2313
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2404
2314
|
|
|
2405
2315
|
await queryClient.prefetchQuery({
|
|
2406
2316
|
queryKey: key,
|
|
@@ -2446,6 +2356,10 @@ describe('createQuery', () => {
|
|
|
2446
2356
|
it('should set status to error if queryFn throws', async () => {
|
|
2447
2357
|
const key = queryKey()
|
|
2448
2358
|
|
|
2359
|
+
const consoleMock = vi
|
|
2360
|
+
.spyOn(console, 'error')
|
|
2361
|
+
.mockImplementation(() => undefined)
|
|
2362
|
+
|
|
2449
2363
|
function Page() {
|
|
2450
2364
|
const state = createQuery(() => ({
|
|
2451
2365
|
queryKey: key,
|
|
@@ -2471,11 +2385,17 @@ describe('createQuery', () => {
|
|
|
2471
2385
|
|
|
2472
2386
|
await waitFor(() => screen.getByText('error'))
|
|
2473
2387
|
await waitFor(() => screen.getByText('Error test jaylen'))
|
|
2388
|
+
|
|
2389
|
+
consoleMock.mockRestore()
|
|
2474
2390
|
})
|
|
2475
2391
|
|
|
2476
2392
|
it('should throw error if queryFn throws and throwOnError is in use', async () => {
|
|
2477
2393
|
const key = queryKey()
|
|
2478
2394
|
|
|
2395
|
+
const consoleMock = vi
|
|
2396
|
+
.spyOn(console, 'error')
|
|
2397
|
+
.mockImplementation(() => undefined)
|
|
2398
|
+
|
|
2479
2399
|
function Page() {
|
|
2480
2400
|
const state = createQuery(() => ({
|
|
2481
2401
|
queryKey: key,
|
|
@@ -2501,6 +2421,8 @@ describe('createQuery', () => {
|
|
|
2501
2421
|
))
|
|
2502
2422
|
|
|
2503
2423
|
await waitFor(() => screen.getByText('error boundary'))
|
|
2424
|
+
|
|
2425
|
+
consoleMock.mockRestore()
|
|
2504
2426
|
})
|
|
2505
2427
|
|
|
2506
2428
|
it('should update with data if we observe no properties and throwOnError', async () => {
|
|
@@ -2719,7 +2641,7 @@ describe('createQuery', () => {
|
|
|
2719
2641
|
|
|
2720
2642
|
it('should always fetch if refetchOnMount is set to always', async () => {
|
|
2721
2643
|
const key = queryKey()
|
|
2722
|
-
const states: CreateQueryResult<string
|
|
2644
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2723
2645
|
|
|
2724
2646
|
await queryClient.prefetchQuery({
|
|
2725
2647
|
queryKey: key,
|
|
@@ -2773,7 +2695,7 @@ describe('createQuery', () => {
|
|
|
2773
2695
|
|
|
2774
2696
|
it('should fetch if initial data is set', async () => {
|
|
2775
2697
|
const key = queryKey()
|
|
2776
|
-
const states: DefinedCreateQueryResult<string
|
|
2698
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2777
2699
|
|
|
2778
2700
|
function Page() {
|
|
2779
2701
|
const state = createQuery(() => ({
|
|
@@ -2811,7 +2733,7 @@ describe('createQuery', () => {
|
|
|
2811
2733
|
|
|
2812
2734
|
it('should not fetch if initial data is set with a stale time', async () => {
|
|
2813
2735
|
const key = queryKey()
|
|
2814
|
-
const states: DefinedCreateQueryResult<string
|
|
2736
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2815
2737
|
|
|
2816
2738
|
function Page() {
|
|
2817
2739
|
const state = createQuery(() => ({
|
|
@@ -2849,7 +2771,7 @@ describe('createQuery', () => {
|
|
|
2849
2771
|
|
|
2850
2772
|
it('should fetch if initial data updated at is older than stale time', async () => {
|
|
2851
2773
|
const key = queryKey()
|
|
2852
|
-
const states: DefinedCreateQueryResult<string
|
|
2774
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2853
2775
|
|
|
2854
2776
|
const oneSecondAgo = Date.now() - 1000
|
|
2855
2777
|
|
|
@@ -2895,7 +2817,7 @@ describe('createQuery', () => {
|
|
|
2895
2817
|
|
|
2896
2818
|
it('should fetch if "initial data updated at" is exactly 0', async () => {
|
|
2897
2819
|
const key = queryKey()
|
|
2898
|
-
const states: DefinedCreateQueryResult<string
|
|
2820
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2899
2821
|
|
|
2900
2822
|
function Page() {
|
|
2901
2823
|
const state = createQuery(() => ({
|
|
@@ -2934,7 +2856,8 @@ describe('createQuery', () => {
|
|
|
2934
2856
|
|
|
2935
2857
|
it('should keep initial data when the query key changes', async () => {
|
|
2936
2858
|
const key = queryKey()
|
|
2937
|
-
const states: Partial<DefinedCreateQueryResult<{ count: number }
|
|
2859
|
+
const states: Array<Partial<DefinedCreateQueryResult<{ count: number }>>> =
|
|
2860
|
+
[]
|
|
2938
2861
|
|
|
2939
2862
|
function Page() {
|
|
2940
2863
|
const [count, setCount] = createSignal(0)
|
|
@@ -2976,7 +2899,7 @@ describe('createQuery', () => {
|
|
|
2976
2899
|
it('should retry specified number of times', async () => {
|
|
2977
2900
|
const key = queryKey()
|
|
2978
2901
|
|
|
2979
|
-
const queryFn = vi.fn<unknown
|
|
2902
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
2980
2903
|
queryFn.mockImplementation(() => {
|
|
2981
2904
|
return Promise.reject(new Error('Error test Barrett'))
|
|
2982
2905
|
})
|
|
@@ -3017,7 +2940,7 @@ describe('createQuery', () => {
|
|
|
3017
2940
|
it('should not retry if retry function `false`', async () => {
|
|
3018
2941
|
const key = queryKey()
|
|
3019
2942
|
|
|
3020
|
-
const queryFn = vi.fn<unknown
|
|
2943
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
3021
2944
|
|
|
3022
2945
|
queryFn.mockImplementationOnce(() => {
|
|
3023
2946
|
return Promise.reject(new Error('Error test Tanner'))
|
|
@@ -3065,7 +2988,7 @@ describe('createQuery', () => {
|
|
|
3065
2988
|
|
|
3066
2989
|
type DelayError = { delay: number }
|
|
3067
2990
|
|
|
3068
|
-
const queryFn = vi.fn<unknown
|
|
2991
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
3069
2992
|
queryFn.mockImplementation(() => {
|
|
3070
2993
|
return Promise.reject({ delay: 50 })
|
|
3071
2994
|
})
|
|
@@ -3167,7 +3090,7 @@ describe('createQuery', () => {
|
|
|
3167
3090
|
|
|
3168
3091
|
it('should fetch on mount when a query was already created with setQueryData', async () => {
|
|
3169
3092
|
const key = queryKey()
|
|
3170
|
-
const states: CreateQueryResult<string
|
|
3093
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3171
3094
|
|
|
3172
3095
|
queryClient.setQueryData(key, 'prefetched')
|
|
3173
3096
|
|
|
@@ -3207,7 +3130,7 @@ describe('createQuery', () => {
|
|
|
3207
3130
|
|
|
3208
3131
|
it('should refetch after focus regain', async () => {
|
|
3209
3132
|
const key = queryKey()
|
|
3210
|
-
const states: CreateQueryResult<string
|
|
3133
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3211
3134
|
|
|
3212
3135
|
// make page unfocused
|
|
3213
3136
|
const visibilityMock = mockVisibilityState('hidden')
|
|
@@ -3274,12 +3197,12 @@ describe('createQuery', () => {
|
|
|
3274
3197
|
// See https://github.com/tannerlinsley/react-query/issues/195
|
|
3275
3198
|
it('should refetch if stale after a prefetch', async () => {
|
|
3276
3199
|
const key = queryKey()
|
|
3277
|
-
const states: CreateQueryResult<string
|
|
3200
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3278
3201
|
|
|
3279
|
-
const queryFn = vi.fn<unknown
|
|
3202
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3280
3203
|
queryFn.mockImplementation(() => 'data')
|
|
3281
3204
|
|
|
3282
|
-
const prefetchQueryFn = vi.fn<unknown
|
|
3205
|
+
const prefetchQueryFn = vi.fn<Array<unknown>, string>()
|
|
3283
3206
|
prefetchQueryFn.mockImplementation(() => 'not yet...')
|
|
3284
3207
|
|
|
3285
3208
|
await queryClient.prefetchQuery({
|
|
@@ -3313,10 +3236,10 @@ describe('createQuery', () => {
|
|
|
3313
3236
|
it('should not refetch if not stale after a prefetch', async () => {
|
|
3314
3237
|
const key = queryKey()
|
|
3315
3238
|
|
|
3316
|
-
const queryFn = vi.fn<unknown
|
|
3239
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3317
3240
|
queryFn.mockImplementation(() => 'data')
|
|
3318
3241
|
|
|
3319
|
-
const prefetchQueryFn = vi.fn<unknown
|
|
3242
|
+
const prefetchQueryFn = vi.fn<Array<unknown>, Promise<string>>()
|
|
3320
3243
|
prefetchQueryFn.mockImplementation(async () => {
|
|
3321
3244
|
await sleep(10)
|
|
3322
3245
|
return 'not yet...'
|
|
@@ -3482,7 +3405,7 @@ describe('createQuery', () => {
|
|
|
3482
3405
|
|
|
3483
3406
|
it('should mark query as fetching, when using initialData', async () => {
|
|
3484
3407
|
const key = queryKey()
|
|
3485
|
-
const results: DefinedCreateQueryResult<string
|
|
3408
|
+
const results: Array<DefinedCreateQueryResult<string>> = []
|
|
3486
3409
|
|
|
3487
3410
|
function Page() {
|
|
3488
3411
|
const result = createQuery(() => ({
|
|
@@ -3517,7 +3440,7 @@ describe('createQuery', () => {
|
|
|
3517
3440
|
|
|
3518
3441
|
it('should initialize state properly, when initialData is falsy', async () => {
|
|
3519
3442
|
const key = queryKey()
|
|
3520
|
-
const results: DefinedCreateQueryResult<number
|
|
3443
|
+
const results: Array<DefinedCreateQueryResult<number>> = []
|
|
3521
3444
|
|
|
3522
3445
|
function Page() {
|
|
3523
3446
|
const result = createQuery(() => ({
|
|
@@ -3549,7 +3472,7 @@ describe('createQuery', () => {
|
|
|
3549
3472
|
// // See https://github.com/tannerlinsley/react-query/issues/214
|
|
3550
3473
|
it('data should persist when enabled is changed to false', async () => {
|
|
3551
3474
|
const key = queryKey()
|
|
3552
|
-
const results: DefinedCreateQueryResult<string
|
|
3475
|
+
const results: Array<DefinedCreateQueryResult<string>> = []
|
|
3553
3476
|
|
|
3554
3477
|
function Page() {
|
|
3555
3478
|
const [shouldFetch, setShouldFetch] = createSignal(true)
|
|
@@ -3589,7 +3512,7 @@ describe('createQuery', () => {
|
|
|
3589
3512
|
|
|
3590
3513
|
it('it should support enabled:false in query object syntax', async () => {
|
|
3591
3514
|
const key = queryKey()
|
|
3592
|
-
const queryFn = vi.fn<unknown
|
|
3515
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3593
3516
|
queryFn.mockImplementation(() => 'data')
|
|
3594
3517
|
|
|
3595
3518
|
function Page() {
|
|
@@ -3699,7 +3622,7 @@ describe('createQuery', () => {
|
|
|
3699
3622
|
|
|
3700
3623
|
it('should not cause memo churn when data does not change', async () => {
|
|
3701
3624
|
const key = queryKey()
|
|
3702
|
-
const queryFn = vi.fn<unknown
|
|
3625
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
3703
3626
|
const memoFn = vi.fn()
|
|
3704
3627
|
|
|
3705
3628
|
function Page() {
|
|
@@ -3782,7 +3705,7 @@ describe('createQuery', () => {
|
|
|
3782
3705
|
it('should refetch in an interval depending on function result', async () => {
|
|
3783
3706
|
const key = queryKey()
|
|
3784
3707
|
let count = 0
|
|
3785
|
-
const states: CreateQueryResult<number
|
|
3708
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
3786
3709
|
|
|
3787
3710
|
function Page() {
|
|
3788
3711
|
const state = createQuery(() => ({
|
|
@@ -3854,7 +3777,7 @@ describe('createQuery', () => {
|
|
|
3854
3777
|
|
|
3855
3778
|
it('should not interval fetch with a refetchInterval of 0', async () => {
|
|
3856
3779
|
const key = queryKey()
|
|
3857
|
-
const states: CreateQueryResult<number
|
|
3780
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
3858
3781
|
|
|
3859
3782
|
function Page() {
|
|
3860
3783
|
const state = createQuery(() => ({
|
|
@@ -3935,7 +3858,7 @@ describe('createQuery', () => {
|
|
|
3935
3858
|
it('should refetch if any query instance becomes enabled', async () => {
|
|
3936
3859
|
const key = queryKey()
|
|
3937
3860
|
|
|
3938
|
-
const queryFn = vi.fn<unknown
|
|
3861
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
3939
3862
|
|
|
3940
3863
|
function Disabled() {
|
|
3941
3864
|
createQuery(() => ({ queryKey: key, queryFn, enabled: false }))
|
|
@@ -3972,7 +3895,7 @@ describe('createQuery', () => {
|
|
|
3972
3895
|
it('should use placeholder data while the query loads', async () => {
|
|
3973
3896
|
const key1 = queryKey()
|
|
3974
3897
|
|
|
3975
|
-
const states: CreateQueryResult<string
|
|
3898
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3976
3899
|
|
|
3977
3900
|
function Page() {
|
|
3978
3901
|
const state = createQuery(() => ({
|
|
@@ -4017,7 +3940,8 @@ describe('createQuery', () => {
|
|
|
4017
3940
|
it('should use placeholder data even for disabled queries', async () => {
|
|
4018
3941
|
const key1 = queryKey()
|
|
4019
3942
|
|
|
4020
|
-
const states: { state: CreateQueryResult<string>; count: number }
|
|
3943
|
+
const states: Array<{ state: CreateQueryResult<string>; count: number }> =
|
|
3944
|
+
[]
|
|
4021
3945
|
|
|
4022
3946
|
function Page() {
|
|
4023
3947
|
const [count, setCount] = createSignal(0)
|
|
@@ -4083,7 +4007,7 @@ describe('createQuery', () => {
|
|
|
4083
4007
|
it('placeholder data should run through select', async () => {
|
|
4084
4008
|
const key1 = queryKey()
|
|
4085
4009
|
|
|
4086
|
-
const states: CreateQueryResult<string
|
|
4010
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4087
4011
|
|
|
4088
4012
|
function Page() {
|
|
4089
4013
|
const state = createQuery(() => ({
|
|
@@ -4129,7 +4053,7 @@ describe('createQuery', () => {
|
|
|
4129
4053
|
it('placeholder data function result should run through select', async () => {
|
|
4130
4054
|
const key1 = queryKey()
|
|
4131
4055
|
|
|
4132
|
-
const states: CreateQueryResult<string
|
|
4056
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4133
4057
|
let placeholderFunctionRunCount = 0
|
|
4134
4058
|
|
|
4135
4059
|
function Page() {
|
|
@@ -4381,7 +4305,7 @@ describe('createQuery', () => {
|
|
|
4381
4305
|
|
|
4382
4306
|
it('should cancel the query if the signal was consumed and there are no more subscriptions', async () => {
|
|
4383
4307
|
const key = queryKey()
|
|
4384
|
-
const states: CreateQueryResult<string
|
|
4308
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4385
4309
|
|
|
4386
4310
|
const queryFn: QueryFunction<
|
|
4387
4311
|
string,
|
|
@@ -4451,7 +4375,7 @@ describe('createQuery', () => {
|
|
|
4451
4375
|
|
|
4452
4376
|
it('should refetch when quickly switching to a failed query', async () => {
|
|
4453
4377
|
const key = queryKey()
|
|
4454
|
-
const states: CreateQueryResult<string
|
|
4378
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4455
4379
|
|
|
4456
4380
|
const queryFn = async () => {
|
|
4457
4381
|
await sleep(50)
|
|
@@ -4501,7 +4425,7 @@ describe('createQuery', () => {
|
|
|
4501
4425
|
|
|
4502
4426
|
it('should update query state and refetch when reset with resetQueries', async () => {
|
|
4503
4427
|
const key = queryKey()
|
|
4504
|
-
const states: CreateQueryResult<number
|
|
4428
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4505
4429
|
let count = 0
|
|
4506
4430
|
|
|
4507
4431
|
function Page() {
|
|
@@ -4575,7 +4499,7 @@ describe('createQuery', () => {
|
|
|
4575
4499
|
|
|
4576
4500
|
it('should update query state and not refetch when resetting a disabled query with resetQueries', async () => {
|
|
4577
4501
|
const key = queryKey()
|
|
4578
|
-
const states: CreateQueryResult<number
|
|
4502
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4579
4503
|
let count = 0
|
|
4580
4504
|
|
|
4581
4505
|
function Page() {
|
|
@@ -4652,11 +4576,10 @@ describe('createQuery', () => {
|
|
|
4652
4576
|
})
|
|
4653
4577
|
})
|
|
4654
4578
|
|
|
4655
|
-
it('should only call the query hash function once
|
|
4579
|
+
it('should only call the query hash function once', async () => {
|
|
4656
4580
|
const key = queryKey()
|
|
4657
4581
|
|
|
4658
4582
|
let hashes = 0
|
|
4659
|
-
let renders = 0
|
|
4660
4583
|
|
|
4661
4584
|
function queryKeyHashFn(x: any) {
|
|
4662
4585
|
hashes++
|
|
@@ -4664,20 +4587,12 @@ describe('createQuery', () => {
|
|
|
4664
4587
|
}
|
|
4665
4588
|
|
|
4666
4589
|
function Page() {
|
|
4667
|
-
|
|
4590
|
+
createQuery(() => ({
|
|
4668
4591
|
queryKey: key,
|
|
4669
4592
|
queryFn: () => 'test',
|
|
4670
4593
|
queryKeyHashFn,
|
|
4671
4594
|
}))
|
|
4672
4595
|
|
|
4673
|
-
createEffect(
|
|
4674
|
-
on(
|
|
4675
|
-
() => state.status,
|
|
4676
|
-
() => {
|
|
4677
|
-
renders++
|
|
4678
|
-
},
|
|
4679
|
-
),
|
|
4680
|
-
)
|
|
4681
4596
|
return null
|
|
4682
4597
|
}
|
|
4683
4598
|
|
|
@@ -4688,12 +4603,11 @@ describe('createQuery', () => {
|
|
|
4688
4603
|
))
|
|
4689
4604
|
|
|
4690
4605
|
await sleep(10)
|
|
4691
|
-
|
|
4692
|
-
expect(renders).toBe(hashes)
|
|
4606
|
+
expect(hashes).toBe(1)
|
|
4693
4607
|
})
|
|
4694
4608
|
|
|
4695
4609
|
it('should refetch when changed enabled to true in error state', async () => {
|
|
4696
|
-
const queryFn = vi.fn<unknown
|
|
4610
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
4697
4611
|
queryFn.mockImplementation(async () => {
|
|
4698
4612
|
await sleep(10)
|
|
4699
4613
|
return Promise.reject(new Error('Suspense Error Bingo'))
|
|
@@ -4888,7 +4802,7 @@ describe('createQuery', () => {
|
|
|
4888
4802
|
|
|
4889
4803
|
it('should have no error in pending state when refetching after error occurred', async () => {
|
|
4890
4804
|
const key = queryKey()
|
|
4891
|
-
const states: CreateQueryResult<number
|
|
4805
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4892
4806
|
const error = new Error('oops')
|
|
4893
4807
|
|
|
4894
4808
|
let count = 0
|
|
@@ -5747,7 +5661,7 @@ describe('createQuery', () => {
|
|
|
5747
5661
|
|
|
5748
5662
|
it('it should have status=error on mount when a query has failed', async () => {
|
|
5749
5663
|
const key = queryKey()
|
|
5750
|
-
const states: CreateQueryResult<unknown
|
|
5664
|
+
const states: Array<CreateQueryResult<unknown>> = []
|
|
5751
5665
|
const error = new Error('oops')
|
|
5752
5666
|
|
|
5753
5667
|
const queryFn = async (): Promise<unknown> => {
|