@tanstack/solid-query 4.11.1 → 4.13.0
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/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/createInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/createMutation.test.d.ts +1 -0
- package/build/lib/__tests__/createQueries.test.d.ts +1 -0
- package/build/lib/__tests__/createQuery.test.d.ts +1 -0
- package/build/lib/__tests__/createQuery.types.test.d.ts +2 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/transition.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsMutating.test.d.ts +1 -0
- package/build/lib/__tests__/utils.d.ts +27 -0
- package/build/solid/__tests__/QueryClientProvider.test.jsx +185 -0
- package/build/solid/__tests__/createInfiniteQuery.test.jsx +1442 -0
- package/build/solid/__tests__/createMutation.test.jsx +857 -0
- package/build/solid/__tests__/createQueries.test.jsx +958 -0
- package/build/solid/__tests__/createQuery.test.jsx +4588 -0
- package/build/solid/__tests__/createQuery.types.test.jsx +124 -0
- package/build/solid/__tests__/suspense.test.jsx +691 -0
- package/build/solid/__tests__/transition.test.jsx +39 -0
- package/build/solid/__tests__/useIsFetching.test.jsx +209 -0
- package/build/solid/__tests__/useIsMutating.test.jsx +216 -0
- package/build/solid/__tests__/utils.jsx +55 -0
- package/build/umd/index.development.js +27 -10
- 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 +5 -6
- package/src/__tests__/createInfiniteQuery.test.tsx +2 -0
- package/src/__tests__/createMutation.test.tsx +65 -1
- package/src/__tests__/createQuery.test.tsx +43 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,11 +33,10 @@
|
|
|
33
33
|
"src"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"jscodeshift": "^0.13.1"
|
|
36
|
+
"solid-jest": "^0.2.0"
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
|
-
"@tanstack/query-core": "4.
|
|
39
|
+
"@tanstack/query-core": "4.13.0"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
42
|
"solid-js": "^1.5.7"
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
"scripts": {
|
|
47
46
|
"clean": "rm -rf ./build",
|
|
48
47
|
"test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src",
|
|
49
|
-
"test:jest": "../../node_modules/.bin/jest --config jest.config.
|
|
50
|
-
"test:
|
|
48
|
+
"test:jest": "../../node_modules/.bin/jest --config ./jest.config.ts",
|
|
49
|
+
"test:dev": "pnpm run test:jest --watch"
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -80,6 +80,7 @@ describe('useInfiniteQuery', () => {
|
|
|
80
80
|
error: null,
|
|
81
81
|
errorUpdatedAt: 0,
|
|
82
82
|
failureCount: 0,
|
|
83
|
+
failureReason: null,
|
|
83
84
|
errorUpdateCount: 0,
|
|
84
85
|
fetchNextPage: expect.any(Function),
|
|
85
86
|
fetchPreviousPage: expect.any(Function),
|
|
@@ -113,6 +114,7 @@ describe('useInfiniteQuery', () => {
|
|
|
113
114
|
error: null,
|
|
114
115
|
errorUpdatedAt: 0,
|
|
115
116
|
failureCount: 0,
|
|
117
|
+
failureReason: null,
|
|
116
118
|
errorUpdateCount: 0,
|
|
117
119
|
fetchNextPage: expect.any(Function),
|
|
118
120
|
fetchPreviousPage: expect.any(Function),
|
|
@@ -170,6 +170,64 @@ describe('useMutation', () => {
|
|
|
170
170
|
expect(onSettledMock).toHaveBeenCalledWith(3)
|
|
171
171
|
})
|
|
172
172
|
|
|
173
|
+
it('should set correct values for `failureReason` and `failureCount` on multiple mutate calls', async () => {
|
|
174
|
+
const [count, setCount] = createSignal(0)
|
|
175
|
+
type Value = { count: number }
|
|
176
|
+
|
|
177
|
+
const mutateFn = jest.fn<Promise<Value>, [value: Value]>()
|
|
178
|
+
|
|
179
|
+
mutateFn.mockImplementationOnce(() => {
|
|
180
|
+
return Promise.reject('Error test Jonas')
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
mutateFn.mockImplementation(async (value) => {
|
|
184
|
+
await sleep(10)
|
|
185
|
+
return Promise.resolve(value)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
function Page() {
|
|
189
|
+
const mutation = createMutation<Value, string, Value>(mutateFn)
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div>
|
|
193
|
+
<h1>Data {mutation.data?.count}</h1>
|
|
194
|
+
<h2>Status {mutation.status}</h2>
|
|
195
|
+
<h2>Failed {mutation.failureCount} times</h2>
|
|
196
|
+
<h2>Failed because {mutation.failureReason ?? 'null'}</h2>
|
|
197
|
+
<button
|
|
198
|
+
onClick={() => {
|
|
199
|
+
setCount((c) => c + 1)
|
|
200
|
+
return mutation.mutate({ count: count() })
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
mutate
|
|
204
|
+
</button>
|
|
205
|
+
</div>
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
render(() => (
|
|
210
|
+
<QueryClientProvider client={queryClient}>
|
|
211
|
+
<Page />
|
|
212
|
+
</QueryClientProvider>
|
|
213
|
+
))
|
|
214
|
+
|
|
215
|
+
await waitFor(() => screen.getByText('Data'))
|
|
216
|
+
|
|
217
|
+
fireEvent.click(screen.getByRole('button', { name: /mutate/i }))
|
|
218
|
+
await waitFor(() => screen.getByText('Data'))
|
|
219
|
+
await waitFor(() => screen.getByText('Status error'))
|
|
220
|
+
await waitFor(() => screen.getByText('Failed 1 times'))
|
|
221
|
+
await waitFor(() => screen.getByText('Failed because Error test Jonas'))
|
|
222
|
+
|
|
223
|
+
fireEvent.click(screen.getByRole('button', { name: /mutate/i }))
|
|
224
|
+
await waitFor(() => screen.getByText('Status loading'))
|
|
225
|
+
await waitFor(() => screen.getByText('Status success'))
|
|
226
|
+
await waitFor(() => screen.getByText('Data 2'))
|
|
227
|
+
await waitFor(() => screen.getByText('Failed 0 times'))
|
|
228
|
+
await waitFor(() => screen.getByText('Failed because null'))
|
|
229
|
+
})
|
|
230
|
+
|
|
173
231
|
it('should be able to call `onError` and `onSettled` after each failed mutate', async () => {
|
|
174
232
|
const onErrorMock = jest.fn()
|
|
175
233
|
const onSettledMock = jest.fn()
|
|
@@ -656,21 +714,25 @@ describe('useMutation', () => {
|
|
|
656
714
|
isLoading: false,
|
|
657
715
|
isPaused: false,
|
|
658
716
|
failureCount: 0,
|
|
717
|
+
failureReason: null,
|
|
659
718
|
})
|
|
660
719
|
expect(states[1]).toMatchObject({
|
|
661
720
|
isLoading: true,
|
|
662
721
|
isPaused: false,
|
|
663
722
|
failureCount: 0,
|
|
723
|
+
failureReason: null,
|
|
664
724
|
})
|
|
665
725
|
expect(states[2]).toMatchObject({
|
|
666
726
|
isLoading: true,
|
|
667
727
|
isPaused: false,
|
|
668
728
|
failureCount: 1,
|
|
729
|
+
failureReason: 'oops',
|
|
669
730
|
})
|
|
670
731
|
expect(states[3]).toMatchObject({
|
|
671
732
|
isLoading: true,
|
|
672
733
|
isPaused: true,
|
|
673
734
|
failureCount: 1,
|
|
735
|
+
failureReason: 'oops',
|
|
674
736
|
})
|
|
675
737
|
|
|
676
738
|
onlineMock.mockReturnValue(true)
|
|
@@ -683,11 +745,13 @@ describe('useMutation', () => {
|
|
|
683
745
|
isLoading: true,
|
|
684
746
|
isPaused: false,
|
|
685
747
|
failureCount: 1,
|
|
748
|
+
failureReason: 'oops',
|
|
686
749
|
})
|
|
687
750
|
expect(states[5]).toMatchObject({
|
|
688
751
|
isLoading: false,
|
|
689
752
|
isPaused: false,
|
|
690
|
-
failureCount:
|
|
753
|
+
failureCount: 0,
|
|
754
|
+
failureReason: null,
|
|
691
755
|
data: 'data',
|
|
692
756
|
})
|
|
693
757
|
|
|
@@ -266,6 +266,7 @@ describe('createQuery', () => {
|
|
|
266
266
|
error: null,
|
|
267
267
|
errorUpdatedAt: 0,
|
|
268
268
|
failureCount: 0,
|
|
269
|
+
failureReason: null,
|
|
269
270
|
errorUpdateCount: 0,
|
|
270
271
|
isError: false,
|
|
271
272
|
isFetched: false,
|
|
@@ -293,6 +294,7 @@ describe('createQuery', () => {
|
|
|
293
294
|
error: null,
|
|
294
295
|
errorUpdatedAt: 0,
|
|
295
296
|
failureCount: 0,
|
|
297
|
+
failureReason: null,
|
|
296
298
|
errorUpdateCount: 0,
|
|
297
299
|
isError: false,
|
|
298
300
|
isFetched: true,
|
|
@@ -338,6 +340,7 @@ describe('createQuery', () => {
|
|
|
338
340
|
<div>
|
|
339
341
|
<h1>Status: {state.status}</h1>
|
|
340
342
|
<div>Failure Count: {state.failureCount}</div>
|
|
343
|
+
<div>Failure Reason: {state.failureReason}</div>
|
|
341
344
|
</div>
|
|
342
345
|
)
|
|
343
346
|
}
|
|
@@ -356,6 +359,7 @@ describe('createQuery', () => {
|
|
|
356
359
|
error: null,
|
|
357
360
|
errorUpdatedAt: 0,
|
|
358
361
|
failureCount: 0,
|
|
362
|
+
failureReason: null,
|
|
359
363
|
errorUpdateCount: 0,
|
|
360
364
|
isError: false,
|
|
361
365
|
isFetched: false,
|
|
@@ -383,6 +387,7 @@ describe('createQuery', () => {
|
|
|
383
387
|
error: null,
|
|
384
388
|
errorUpdatedAt: 0,
|
|
385
389
|
failureCount: 1,
|
|
390
|
+
failureReason: 'rejected',
|
|
386
391
|
errorUpdateCount: 0,
|
|
387
392
|
isError: false,
|
|
388
393
|
isFetched: false,
|
|
@@ -410,6 +415,7 @@ describe('createQuery', () => {
|
|
|
410
415
|
error: 'rejected',
|
|
411
416
|
errorUpdatedAt: expect.any(Number),
|
|
412
417
|
failureCount: 2,
|
|
418
|
+
failureReason: 'rejected',
|
|
413
419
|
errorUpdateCount: 1,
|
|
414
420
|
isError: true,
|
|
415
421
|
isFetched: true,
|
|
@@ -2562,48 +2568,6 @@ describe('createQuery', () => {
|
|
|
2562
2568
|
expect(queryCache.find(key())!.options.queryFn).toBe(queryFn1)
|
|
2563
2569
|
})
|
|
2564
2570
|
|
|
2565
|
-
// TODO(lukemurray): this seems like a react implementation detail
|
|
2566
|
-
it.skip('should render correct states even in case of useEffect triggering delays', async () => {
|
|
2567
|
-
const key = queryKey()
|
|
2568
|
-
const states: CreateQueryResult<string>[] = []
|
|
2569
|
-
|
|
2570
|
-
// @ts-expect-error - we skip this test
|
|
2571
|
-
const originalUseEffect = NotReact.useEffect
|
|
2572
|
-
|
|
2573
|
-
// Try to simulate useEffect timing delay
|
|
2574
|
-
// @ts-ignore
|
|
2575
|
-
NotReact.useEffect = (...args: any[]) => {
|
|
2576
|
-
originalUseEffect(() => {
|
|
2577
|
-
setTimeout(() => {
|
|
2578
|
-
args[0]()
|
|
2579
|
-
}, 10)
|
|
2580
|
-
}, args[1])
|
|
2581
|
-
}
|
|
2582
|
-
|
|
2583
|
-
function Page() {
|
|
2584
|
-
const state = createQuery(key, () => 'data', { staleTime: Infinity })
|
|
2585
|
-
createRenderEffect(() => {
|
|
2586
|
-
states.push({ ...state })
|
|
2587
|
-
})
|
|
2588
|
-
return null
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
render(() => (
|
|
2592
|
-
<QueryClientProvider client={queryClient}>
|
|
2593
|
-
<Page />
|
|
2594
|
-
</QueryClientProvider>
|
|
2595
|
-
))
|
|
2596
|
-
queryClient.setQueryData(key(), 'data')
|
|
2597
|
-
await sleep(50)
|
|
2598
|
-
|
|
2599
|
-
// @ts-ignore
|
|
2600
|
-
NotReact.useEffect = originalUseEffect
|
|
2601
|
-
|
|
2602
|
-
expect(states.length).toBe(2)
|
|
2603
|
-
expect(states[0]).toMatchObject({ status: 'loading' })
|
|
2604
|
-
expect(states[1]).toMatchObject({ status: 'success' })
|
|
2605
|
-
})
|
|
2606
|
-
|
|
2607
2571
|
it('should batch re-renders', async () => {
|
|
2608
2572
|
const key = queryKey()
|
|
2609
2573
|
|
|
@@ -3280,6 +3244,7 @@ describe('createQuery', () => {
|
|
|
3280
3244
|
<div>
|
|
3281
3245
|
<div>error: {result.error ?? 'null'}</div>
|
|
3282
3246
|
<div>failureCount: {result.failureCount}</div>
|
|
3247
|
+
<div>failureReason: {result.failureReason}</div>
|
|
3283
3248
|
</div>
|
|
3284
3249
|
)
|
|
3285
3250
|
}
|
|
@@ -3304,6 +3269,7 @@ describe('createQuery', () => {
|
|
|
3304
3269
|
))
|
|
3305
3270
|
|
|
3306
3271
|
await waitFor(() => screen.getByText('failureCount: 1'))
|
|
3272
|
+
await waitFor(() => screen.getByText('failureReason: some error'))
|
|
3307
3273
|
fireEvent.click(screen.getByRole('button', { name: /hide/i }))
|
|
3308
3274
|
await waitFor(() => screen.getByRole('button', { name: /show/i }))
|
|
3309
3275
|
fireEvent.click(screen.getByRole('button', { name: /show/i }))
|
|
@@ -3334,6 +3300,7 @@ describe('createQuery', () => {
|
|
|
3334
3300
|
<div>
|
|
3335
3301
|
<div>error: {result.error ?? 'null'}</div>
|
|
3336
3302
|
<div>failureCount: {result.failureCount}</div>
|
|
3303
|
+
<div>failureReason: {result.failureReason}</div>
|
|
3337
3304
|
</div>
|
|
3338
3305
|
)
|
|
3339
3306
|
}
|
|
@@ -3363,6 +3330,7 @@ describe('createQuery', () => {
|
|
|
3363
3330
|
))
|
|
3364
3331
|
|
|
3365
3332
|
await waitFor(() => screen.getByText('failureCount: 1'))
|
|
3333
|
+
await waitFor(() => screen.getByText('failureReason: some error'))
|
|
3366
3334
|
fireEvent.click(screen.getByRole('button', { name: /hide/i }))
|
|
3367
3335
|
fireEvent.click(screen.getByRole('button', { name: /cancel/i }))
|
|
3368
3336
|
await waitFor(() => screen.getByRole('button', { name: /show/i }))
|
|
@@ -3626,7 +3594,7 @@ describe('createQuery', () => {
|
|
|
3626
3594
|
})
|
|
3627
3595
|
|
|
3628
3596
|
function Page() {
|
|
3629
|
-
const state = createQuery(key, queryFn, {
|
|
3597
|
+
const state = createQuery<unknown, string>(key, queryFn, {
|
|
3630
3598
|
retry: 1,
|
|
3631
3599
|
retryDelay: 1,
|
|
3632
3600
|
})
|
|
@@ -3635,6 +3603,7 @@ describe('createQuery', () => {
|
|
|
3635
3603
|
<div>
|
|
3636
3604
|
<h1>{state.status}</h1>
|
|
3637
3605
|
<h2>Failed {state.failureCount} times</h2>
|
|
3606
|
+
<h2>Failed because {state.failureReason}</h2>
|
|
3638
3607
|
</div>
|
|
3639
3608
|
)
|
|
3640
3609
|
}
|
|
@@ -3650,6 +3619,7 @@ describe('createQuery', () => {
|
|
|
3650
3619
|
|
|
3651
3620
|
// query should fail `retry + 1` times, since first time isn't a "retry"
|
|
3652
3621
|
await waitFor(() => screen.getByText('Failed 2 times'))
|
|
3622
|
+
await waitFor(() => screen.getByText('Failed because Error test Barrett'))
|
|
3653
3623
|
|
|
3654
3624
|
expect(queryFn).toHaveBeenCalledTimes(2)
|
|
3655
3625
|
})
|
|
@@ -3677,6 +3647,7 @@ describe('createQuery', () => {
|
|
|
3677
3647
|
<div>
|
|
3678
3648
|
<h1>{state.status}</h1>
|
|
3679
3649
|
<h2>Failed {state.failureCount} times</h2>
|
|
3650
|
+
<h2>Failed because {state.failureReason}</h2>
|
|
3680
3651
|
<h2>{state.error}</h2>
|
|
3681
3652
|
</div>
|
|
3682
3653
|
)
|
|
@@ -3690,8 +3661,8 @@ describe('createQuery', () => {
|
|
|
3690
3661
|
|
|
3691
3662
|
await waitFor(() => screen.getByText('loading'))
|
|
3692
3663
|
await waitFor(() => screen.getByText('error'))
|
|
3693
|
-
|
|
3694
3664
|
await waitFor(() => screen.getByText('Failed 2 times'))
|
|
3665
|
+
await waitFor(() => screen.getByText('Failed because NoRetry'))
|
|
3695
3666
|
await waitFor(() => screen.getByText('NoRetry'))
|
|
3696
3667
|
|
|
3697
3668
|
expect(queryFn).toHaveBeenCalledTimes(2)
|
|
@@ -3708,7 +3679,7 @@ describe('createQuery', () => {
|
|
|
3708
3679
|
})
|
|
3709
3680
|
|
|
3710
3681
|
function Page() {
|
|
3711
|
-
const state = createQuery(key, queryFn, {
|
|
3682
|
+
const state = createQuery<unknown, DelayError>(key, queryFn, {
|
|
3712
3683
|
retry: 1,
|
|
3713
3684
|
retryDelay: (_, error: DelayError) => error.delay,
|
|
3714
3685
|
})
|
|
@@ -3717,6 +3688,7 @@ describe('createQuery', () => {
|
|
|
3717
3688
|
<div>
|
|
3718
3689
|
<h1>{state.status}</h1>
|
|
3719
3690
|
<h2>Failed {state.failureCount} times</h2>
|
|
3691
|
+
<h2>Failed because DelayError: {state.failureReason?.delay}ms</h2>
|
|
3720
3692
|
</div>
|
|
3721
3693
|
)
|
|
3722
3694
|
}
|
|
@@ -3731,6 +3703,7 @@ describe('createQuery', () => {
|
|
|
3731
3703
|
|
|
3732
3704
|
expect(queryFn).toHaveBeenCalledTimes(1)
|
|
3733
3705
|
|
|
3706
|
+
await waitFor(() => screen.getByText('Failed because DelayError: 50ms'))
|
|
3734
3707
|
await waitFor(() => screen.getByText('Failed 2 times'))
|
|
3735
3708
|
|
|
3736
3709
|
expect(queryFn).toHaveBeenCalledTimes(2)
|
|
@@ -3746,7 +3719,7 @@ describe('createQuery', () => {
|
|
|
3746
3719
|
let count = 0
|
|
3747
3720
|
|
|
3748
3721
|
function Page() {
|
|
3749
|
-
const query = createQuery(
|
|
3722
|
+
const query = createQuery<unknown, string>(
|
|
3750
3723
|
key,
|
|
3751
3724
|
() => {
|
|
3752
3725
|
count++
|
|
@@ -3763,6 +3736,7 @@ describe('createQuery', () => {
|
|
|
3763
3736
|
<div>error {String(query.error)}</div>
|
|
3764
3737
|
<div>status {query.status}</div>
|
|
3765
3738
|
<div>failureCount {query.failureCount}</div>
|
|
3739
|
+
<div>failureReason {query.failureReason}</div>
|
|
3766
3740
|
</div>
|
|
3767
3741
|
)
|
|
3768
3742
|
}
|
|
@@ -3775,24 +3749,28 @@ describe('createQuery', () => {
|
|
|
3775
3749
|
|
|
3776
3750
|
// The query should display the first error result
|
|
3777
3751
|
await waitFor(() => screen.getByText('failureCount 1'))
|
|
3752
|
+
await waitFor(() => screen.getByText('failureReason fetching error 1'))
|
|
3778
3753
|
await waitFor(() => screen.getByText('status loading'))
|
|
3779
3754
|
await waitFor(() => screen.getByText('error null'))
|
|
3780
3755
|
|
|
3781
3756
|
// Check if the query really paused
|
|
3782
3757
|
await sleep(10)
|
|
3783
3758
|
await waitFor(() => screen.getByText('failureCount 1'))
|
|
3759
|
+
await waitFor(() => screen.getByText('failureReason fetching error 1'))
|
|
3784
3760
|
|
|
3785
3761
|
visibilityMock.mockRestore()
|
|
3786
3762
|
window.dispatchEvent(new FocusEvent('focus'))
|
|
3787
3763
|
|
|
3788
3764
|
// Wait for the final result
|
|
3789
3765
|
await waitFor(() => screen.getByText('failureCount 4'))
|
|
3766
|
+
await waitFor(() => screen.getByText('failureReason fetching error 4'))
|
|
3790
3767
|
await waitFor(() => screen.getByText('status error'))
|
|
3791
3768
|
await waitFor(() => screen.getByText('error fetching error 4'))
|
|
3792
3769
|
|
|
3793
3770
|
// Check if the query really stopped
|
|
3794
3771
|
await sleep(10)
|
|
3795
3772
|
await waitFor(() => screen.getByText('failureCount 4'))
|
|
3773
|
+
await waitFor(() => screen.getByText('failureReason fetching error 4'))
|
|
3796
3774
|
|
|
3797
3775
|
// Check if the error has been logged in the console
|
|
3798
3776
|
expect(mockLogger.error).toHaveBeenCalledWith('fetching error 4')
|
|
@@ -3973,13 +3951,13 @@ describe('createQuery', () => {
|
|
|
3973
3951
|
})
|
|
3974
3952
|
|
|
3975
3953
|
// See https://github.com/tannerlinsley/react-query/issues/190
|
|
3976
|
-
it('should reset failureCount on successful fetch', async () => {
|
|
3954
|
+
it('should reset failureCount and failureReason on successful fetch', async () => {
|
|
3977
3955
|
const key = queryKey()
|
|
3978
3956
|
|
|
3979
3957
|
function Page() {
|
|
3980
3958
|
let counter = 0
|
|
3981
3959
|
|
|
3982
|
-
const query = createQuery(
|
|
3960
|
+
const query = createQuery<unknown, Error>(
|
|
3983
3961
|
key,
|
|
3984
3962
|
async () => {
|
|
3985
3963
|
if (counter < 2) {
|
|
@@ -3995,6 +3973,7 @@ describe('createQuery', () => {
|
|
|
3995
3973
|
return (
|
|
3996
3974
|
<div>
|
|
3997
3975
|
<div>failureCount {query.failureCount}</div>
|
|
3976
|
+
<div>failureReason {query.failureReason?.message ?? 'null'}</div>
|
|
3998
3977
|
</div>
|
|
3999
3978
|
)
|
|
4000
3979
|
}
|
|
@@ -4006,7 +3985,9 @@ describe('createQuery', () => {
|
|
|
4006
3985
|
))
|
|
4007
3986
|
|
|
4008
3987
|
await waitFor(() => screen.getByText('failureCount 2'))
|
|
3988
|
+
await waitFor(() => screen.getByText('failureReason error'))
|
|
4009
3989
|
await waitFor(() => screen.getByText('failureCount 0'))
|
|
3990
|
+
await waitFor(() => screen.getByText('failureReason null'))
|
|
4010
3991
|
})
|
|
4011
3992
|
|
|
4012
3993
|
// See https://github.com/tannerlinsley/react-query/issues/199
|
|
@@ -5595,7 +5576,7 @@ describe('createQuery', () => {
|
|
|
5595
5576
|
let count = 0
|
|
5596
5577
|
|
|
5597
5578
|
function Page() {
|
|
5598
|
-
const state = createQuery({
|
|
5579
|
+
const state = createQuery<unknown, string, string>({
|
|
5599
5580
|
queryKey: key,
|
|
5600
5581
|
queryFn: async () => {
|
|
5601
5582
|
count++
|
|
@@ -5610,6 +5591,7 @@ describe('createQuery', () => {
|
|
|
5610
5591
|
status: {state.status}, fetchStatus: {state.fetchStatus},
|
|
5611
5592
|
failureCount: {state.failureCount}
|
|
5612
5593
|
</div>
|
|
5594
|
+
<div>failureReason: {state.failureReason ?? 'null'}</div>
|
|
5613
5595
|
<div>data: {state.data}</div>
|
|
5614
5596
|
<button
|
|
5615
5597
|
onClick={() => queryClient.invalidateQueries({ queryKey: key() })}
|
|
@@ -5636,6 +5618,7 @@ describe('createQuery', () => {
|
|
|
5636
5618
|
'status: success, fetchStatus: paused, failureCount: 0',
|
|
5637
5619
|
),
|
|
5638
5620
|
)
|
|
5621
|
+
await waitFor(() => screen.getByText('failureReason: null'))
|
|
5639
5622
|
|
|
5640
5623
|
onlineMock.mockReturnValue(true)
|
|
5641
5624
|
window.dispatchEvent(new Event('online'))
|
|
@@ -5645,9 +5628,11 @@ describe('createQuery', () => {
|
|
|
5645
5628
|
'status: success, fetchStatus: fetching, failureCount: 0',
|
|
5646
5629
|
),
|
|
5647
5630
|
)
|
|
5631
|
+
await waitFor(() => screen.getByText('failureReason: null'))
|
|
5648
5632
|
await waitFor(() =>
|
|
5649
5633
|
screen.getByText('status: success, fetchStatus: idle, failureCount: 0'),
|
|
5650
5634
|
)
|
|
5635
|
+
await waitFor(() => screen.getByText('failureReason: null'))
|
|
5651
5636
|
|
|
5652
5637
|
await waitFor(() => {
|
|
5653
5638
|
expect(screen.getByText('data: data2')).toBeInTheDocument()
|
|
@@ -5898,7 +5883,7 @@ describe('createQuery', () => {
|
|
|
5898
5883
|
let count = 0
|
|
5899
5884
|
|
|
5900
5885
|
function Page() {
|
|
5901
|
-
const state = createQuery({
|
|
5886
|
+
const state = createQuery<unknown, Error>({
|
|
5902
5887
|
queryKey: key,
|
|
5903
5888
|
queryFn: async (): Promise<unknown> => {
|
|
5904
5889
|
count++
|
|
@@ -5915,6 +5900,7 @@ describe('createQuery', () => {
|
|
|
5915
5900
|
status: {state.status}, fetchStatus: {state.fetchStatus},
|
|
5916
5901
|
failureCount: {state.failureCount}
|
|
5917
5902
|
</div>
|
|
5903
|
+
<div>failureReason: {state.failureReason?.message ?? 'null'}</div>
|
|
5918
5904
|
</div>
|
|
5919
5905
|
)
|
|
5920
5906
|
}
|
|
@@ -5930,6 +5916,7 @@ describe('createQuery', () => {
|
|
|
5930
5916
|
'status: loading, fetchStatus: fetching, failureCount: 1',
|
|
5931
5917
|
),
|
|
5932
5918
|
)
|
|
5919
|
+
await waitFor(() => screen.getByText('failureReason: failed1'))
|
|
5933
5920
|
|
|
5934
5921
|
const onlineMock = mockNavigatorOnLine(false)
|
|
5935
5922
|
|
|
@@ -5940,6 +5927,7 @@ describe('createQuery', () => {
|
|
|
5940
5927
|
'status: loading, fetchStatus: paused, failureCount: 1',
|
|
5941
5928
|
),
|
|
5942
5929
|
)
|
|
5930
|
+
await waitFor(() => screen.getByText('failureReason: failed1'))
|
|
5943
5931
|
|
|
5944
5932
|
expect(count).toBe(1)
|
|
5945
5933
|
|
|
@@ -5949,6 +5937,7 @@ describe('createQuery', () => {
|
|
|
5949
5937
|
await waitFor(() =>
|
|
5950
5938
|
screen.getByText('status: error, fetchStatus: idle, failureCount: 3'),
|
|
5951
5939
|
)
|
|
5940
|
+
await waitFor(() => screen.getByText('failureReason: failed3'))
|
|
5952
5941
|
|
|
5953
5942
|
expect(count).toBe(3)
|
|
5954
5943
|
|
|
@@ -6261,7 +6250,7 @@ describe('createQuery', () => {
|
|
|
6261
6250
|
let count = 0
|
|
6262
6251
|
|
|
6263
6252
|
function Page() {
|
|
6264
|
-
const state = createQuery({
|
|
6253
|
+
const state = createQuery<unknown, Error>({
|
|
6265
6254
|
queryKey: key,
|
|
6266
6255
|
queryFn: async (): Promise<unknown> => {
|
|
6267
6256
|
count++
|
|
@@ -6279,6 +6268,7 @@ describe('createQuery', () => {
|
|
|
6279
6268
|
status: {state.status}, fetchStatus: {state.fetchStatus},
|
|
6280
6269
|
failureCount: {state.failureCount}
|
|
6281
6270
|
</div>
|
|
6271
|
+
<div>failureReason: {state.failureReason?.message ?? 'null'}</div>
|
|
6282
6272
|
</div>
|
|
6283
6273
|
)
|
|
6284
6274
|
}
|
|
@@ -6294,6 +6284,7 @@ describe('createQuery', () => {
|
|
|
6294
6284
|
'status: loading, fetchStatus: paused, failureCount: 1',
|
|
6295
6285
|
),
|
|
6296
6286
|
)
|
|
6287
|
+
await waitFor(() => screen.getByText('failureReason: failed1'))
|
|
6297
6288
|
|
|
6298
6289
|
expect(count).toBe(1)
|
|
6299
6290
|
|
|
@@ -6303,6 +6294,7 @@ describe('createQuery', () => {
|
|
|
6303
6294
|
await waitFor(() =>
|
|
6304
6295
|
screen.getByText('status: error, fetchStatus: idle, failureCount: 3'),
|
|
6305
6296
|
)
|
|
6297
|
+
await waitFor(() => screen.getByText('failureReason: failed3'))
|
|
6306
6298
|
|
|
6307
6299
|
expect(count).toBe(3)
|
|
6308
6300
|
|