@tanstack/react-query 5.0.0-alpha.7 → 5.0.0-alpha.71
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/codemods/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/remove-overloads/utils/index.js +124 -0
- package/build/codemods/remove-overloads/utils/unknown-usage-error.js +27 -0
- package/build/codemods/src/utils/index.js +205 -0
- package/build/codemods/src/v4/key-transformation.js +138 -0
- package/build/codemods/src/v4/replace-import-specifier.js +25 -0
- package/build/codemods/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/transformers/query-client-transformer.js +48 -0
- package/build/codemods/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/utils/replacers/key-replacer.js +164 -0
- package/build/lib/HydrationBoundary.cjs +50 -0
- package/build/lib/{HydrationBoundary.mjs.map → HydrationBoundary.cjs.map} +1 -1
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.js +9 -29
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/HydrationBoundary.legacy.cjs +50 -0
- package/build/lib/HydrationBoundary.legacy.cjs.map +1 -0
- package/build/lib/{HydrationBoundary.esm.js → HydrationBoundary.legacy.js} +3 -2
- package/build/lib/HydrationBoundary.legacy.js.map +1 -0
- package/build/lib/QueryClientProvider.cjs +54 -0
- package/build/lib/QueryClientProvider.cjs.map +1 -0
- package/build/lib/QueryClientProvider.d.ts +2 -1
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.js +7 -29
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryClientProvider.legacy.cjs +54 -0
- package/build/lib/QueryClientProvider.legacy.cjs.map +1 -0
- package/build/lib/{QueryClientProvider.esm.js → QueryClientProvider.legacy.js} +2 -1
- package/build/lib/QueryClientProvider.legacy.js.map +1 -0
- package/build/lib/QueryErrorResetBoundary.cjs +60 -0
- package/build/lib/{QueryErrorResetBoundary.mjs.map → QueryErrorResetBoundary.cjs.map} +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +1 -0
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.js +7 -28
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.legacy.cjs +60 -0
- package/build/lib/QueryErrorResetBoundary.legacy.cjs.map +1 -0
- package/build/lib/{QueryErrorResetBoundary.esm.js → QueryErrorResetBoundary.legacy.js} +2 -1
- package/build/lib/QueryErrorResetBoundary.legacy.js.map +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr.test.d.ts +1 -0
- package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.d.ts +3 -2
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.cjs +51 -0
- package/build/lib/errorBoundaryUtils.cjs.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.js +8 -30
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/errorBoundaryUtils.legacy.cjs +51 -0
- package/build/lib/errorBoundaryUtils.legacy.cjs.map +1 -0
- package/build/lib/{errorBoundaryUtils.esm.js → errorBoundaryUtils.legacy.js} +6 -5
- package/build/lib/errorBoundaryUtils.legacy.js.map +1 -0
- package/build/lib/index.cjs +40 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.d.ts +2 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +12 -37
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.legacy.cjs +40 -0
- package/build/lib/index.legacy.cjs.map +1 -0
- package/build/lib/index.legacy.js +13 -0
- package/build/lib/index.legacy.js.map +1 -0
- package/build/lib/isRestoring.cjs +31 -0
- package/build/lib/isRestoring.cjs.map +1 -0
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.js +5 -26
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/isRestoring.legacy.cjs +31 -0
- package/build/lib/isRestoring.legacy.cjs.map +1 -0
- package/build/lib/{isRestoring.esm.js → isRestoring.legacy.js} +2 -1
- package/build/lib/isRestoring.legacy.js.map +1 -0
- package/build/lib/queryOptions.cjs +8 -0
- package/build/lib/queryOptions.cjs.map +1 -0
- package/build/lib/queryOptions.d.ts +11 -0
- package/build/lib/queryOptions.d.ts.map +1 -0
- package/build/lib/queryOptions.js +6 -0
- package/build/lib/queryOptions.js.map +1 -0
- package/build/lib/queryOptions.legacy.cjs +8 -0
- package/build/lib/queryOptions.legacy.cjs.map +1 -0
- package/build/lib/queryOptions.legacy.js +6 -0
- package/build/lib/queryOptions.legacy.js.map +1 -0
- package/build/lib/suspense.cjs +22 -0
- package/build/lib/suspense.cjs.map +1 -0
- package/build/lib/suspense.d.ts +3 -5
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.js +3 -15
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/{suspense.esm.js → suspense.legacy.cjs} +8 -10
- package/build/lib/suspense.legacy.cjs.map +1 -0
- package/build/lib/{suspense.mjs → suspense.legacy.js} +3 -10
- package/build/lib/suspense.legacy.js.map +1 -0
- package/build/lib/types.d.ts +11 -10
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.cjs +80 -0
- package/build/lib/useBaseQuery.cjs.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.js +30 -54
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.legacy.cjs +80 -0
- package/build/lib/useBaseQuery.legacy.cjs.map +1 -0
- package/build/lib/{useBaseQuery.mjs → useBaseQuery.legacy.js} +16 -19
- package/build/lib/useBaseQuery.legacy.js.map +1 -0
- package/build/lib/useInfiniteQuery.cjs +15 -0
- package/build/lib/useInfiniteQuery.cjs.map +1 -0
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.js +6 -7
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.legacy.cjs +15 -0
- package/build/lib/useInfiniteQuery.legacy.cjs.map +1 -0
- package/build/lib/{useInfiniteQuery.esm.js → useInfiniteQuery.legacy.js} +3 -2
- package/build/lib/useInfiniteQuery.legacy.js.map +1 -0
- package/build/lib/useIsFetching.cjs +34 -0
- package/build/lib/useIsFetching.cjs.map +1 -0
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.js +7 -27
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.legacy.cjs +34 -0
- package/build/lib/useIsFetching.legacy.cjs.map +1 -0
- package/build/lib/{useIsFetching.esm.js → useIsFetching.legacy.js} +3 -2
- package/build/lib/useIsFetching.legacy.js.map +1 -0
- package/build/lib/useMutation.cjs +54 -0
- package/build/lib/useMutation.cjs.map +1 -0
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.js +12 -32
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.legacy.cjs +54 -0
- package/build/lib/useMutation.legacy.cjs.map +1 -0
- package/build/lib/{useMutation.esm.js → useMutation.legacy.js} +5 -4
- package/build/lib/useMutation.legacy.js.map +1 -0
- package/build/lib/useMutationState.cjs +60 -0
- package/build/lib/useMutationState.cjs.map +1 -0
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.js +13 -34
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useMutationState.legacy.cjs +60 -0
- package/build/lib/useMutationState.legacy.cjs.map +1 -0
- package/build/lib/{useMutationState.esm.js → useMutationState.legacy.js} +3 -2
- package/build/lib/useMutationState.legacy.js.map +1 -0
- package/build/lib/useQueries.cjs +99 -0
- package/build/lib/useQueries.cjs.map +1 -0
- package/build/lib/useQueries.d.ts +10 -8
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.js +52 -67
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.legacy.cjs +102 -0
- package/build/lib/useQueries.legacy.cjs.map +1 -0
- package/build/lib/{useQueries.esm.js → useQueries.legacy.js} +37 -28
- package/build/lib/useQueries.legacy.js.map +1 -0
- package/build/lib/useQuery.cjs +14 -0
- package/build/lib/useQuery.cjs.map +1 -0
- package/build/lib/useQuery.d.ts +3 -8
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.js +5 -6
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.legacy.cjs +14 -0
- package/build/lib/useQuery.legacy.cjs.map +1 -0
- package/build/lib/{useQuery.esm.js → useQuery.legacy.js} +3 -2
- package/build/lib/useQuery.legacy.js.map +1 -0
- package/build/lib/{utils.mjs → utils.cjs} +4 -2
- package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +1 -3
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.legacy.cjs +12 -0
- package/build/lib/utils.legacy.cjs.map +1 -0
- package/build/lib/{utils.esm.js → utils.legacy.js} +1 -1
- package/build/lib/utils.legacy.js.map +1 -0
- package/package.json +25 -15
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +752 -620
- package/src/__tests__/ssr-hydration.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +6 -88
- package/src/__tests__/useInfiniteQuery.type.test.tsx +0 -27
- package/src/__tests__/useMutation.test.tsx +4 -4
- package/src/__tests__/useMutationState.test.tsx +23 -0
- package/src/__tests__/useQueries.test.tsx +206 -83
- package/src/__tests__/useQuery.test.tsx +246 -338
- package/src/__tests__/useQuery.types.test.tsx +21 -0
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -0
- package/src/queryOptions.ts +42 -0
- package/src/suspense.ts +9 -15
- package/src/useBaseQuery.ts +12 -23
- package/src/useInfiniteQuery.ts +1 -0
- package/src/useIsFetching.ts +1 -0
- package/src/useMutation.ts +2 -1
- package/src/useMutationState.ts +4 -3
- package/src/useQueries.ts +44 -26
- package/src/useQuery.ts +5 -17
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/HydrationBoundary.mjs +0 -28
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -30
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.mjs +0 -37
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.mjs +0 -27
- package/build/lib/errorBoundaryUtils.mjs.map +0 -1
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/isRestoring.mjs +0 -8
- package/build/lib/isRestoring.mjs.map +0 -1
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/suspense.mjs.map +0 -1
- package/build/lib/useBaseQuery.esm.js +0 -62
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useBaseQuery.mjs.map +0 -1
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.mjs +0 -12
- package/build/lib/useInfiniteQuery.mjs.map +0 -1
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -12
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutation.mjs +0 -32
- package/build/lib/useMutation.mjs.map +0 -1
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useMutationState.mjs +0 -37
- package/build/lib/useMutationState.mjs.map +0 -1
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQueries.mjs +0 -69
- package/build/lib/useQueries.mjs.map +0 -1
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/useQuery.mjs +0 -11
- package/build/lib/useQuery.mjs.map +0 -1
- package/build/lib/utils.esm.js.map +0 -1
- package/build/umd/index.development.js +0 -3040
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
- /package/src/{isRestoring.tsx → isRestoring.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import ReactDOM from 'react-dom'
|
|
3
|
-
import ReactDOMTestUtils from 'react-dom/test-utils'
|
|
4
|
-
import ReactDOMServer from 'react-dom/server'
|
|
3
|
+
import * as ReactDOMTestUtils from 'react-dom/test-utils'
|
|
4
|
+
import * as ReactDOMServer from 'react-dom/server'
|
|
5
5
|
// eslint-disable-next-line import/no-unresolved -- types only for module augmentation
|
|
6
6
|
import type {} from 'react-dom/next'
|
|
7
7
|
import { vi } from 'vitest'
|
|
@@ -190,88 +190,6 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
190
190
|
expect(queryCache.find({ queryKey: key })?.getObserversCount()).toBe(0)
|
|
191
191
|
})
|
|
192
192
|
|
|
193
|
-
it('should call onSuccess on the first successful call', async () => {
|
|
194
|
-
const key = queryKey()
|
|
195
|
-
|
|
196
|
-
const successFn = vi.fn()
|
|
197
|
-
|
|
198
|
-
function Page() {
|
|
199
|
-
useQuery({
|
|
200
|
-
queryKey: [key],
|
|
201
|
-
queryFn: async () => {
|
|
202
|
-
await sleep(10)
|
|
203
|
-
return key
|
|
204
|
-
},
|
|
205
|
-
suspense: true,
|
|
206
|
-
select: () => 'selected',
|
|
207
|
-
onSuccess: successFn,
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
return <>rendered</>
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const rendered = renderWithClient(
|
|
214
|
-
queryClient,
|
|
215
|
-
<React.Suspense fallback="loading">
|
|
216
|
-
<Page />
|
|
217
|
-
</React.Suspense>,
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
await waitFor(() => rendered.getByText('rendered'))
|
|
221
|
-
|
|
222
|
-
await waitFor(() => expect(successFn).toHaveBeenCalledTimes(1))
|
|
223
|
-
await waitFor(() => expect(successFn).toHaveBeenCalledWith('selected'))
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('should call every onSuccess handler within a suspense boundary', async () => {
|
|
227
|
-
const key = queryKey()
|
|
228
|
-
|
|
229
|
-
const successFn1 = vi.fn()
|
|
230
|
-
const successFn2 = vi.fn()
|
|
231
|
-
|
|
232
|
-
function FirstComponent() {
|
|
233
|
-
useQuery({
|
|
234
|
-
queryKey: key,
|
|
235
|
-
queryFn: () => {
|
|
236
|
-
sleep(10)
|
|
237
|
-
return 'data'
|
|
238
|
-
},
|
|
239
|
-
suspense: true,
|
|
240
|
-
onSuccess: successFn1,
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
return <span>first</span>
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function SecondComponent() {
|
|
247
|
-
useQuery({
|
|
248
|
-
queryKey: key,
|
|
249
|
-
queryFn: () => {
|
|
250
|
-
sleep(10)
|
|
251
|
-
return 'data'
|
|
252
|
-
},
|
|
253
|
-
|
|
254
|
-
suspense: true,
|
|
255
|
-
onSuccess: successFn2,
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
return <span>second</span>
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const rendered = renderWithClient(
|
|
262
|
-
queryClient,
|
|
263
|
-
<React.Suspense fallback="loading">
|
|
264
|
-
<FirstComponent />
|
|
265
|
-
<SecondComponent />
|
|
266
|
-
</React.Suspense>,
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
await waitFor(() => rendered.getByText('second'))
|
|
270
|
-
|
|
271
|
-
await waitFor(() => expect(successFn1).toHaveBeenCalledTimes(1))
|
|
272
|
-
await waitFor(() => expect(successFn2).toHaveBeenCalledTimes(1))
|
|
273
|
-
})
|
|
274
|
-
|
|
275
193
|
// https://github.com/tannerlinsley/react-query/issues/468
|
|
276
194
|
it('should reset error state if new component instances are mounted', async () => {
|
|
277
195
|
const consoleMock = vi
|
|
@@ -616,7 +534,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
616
534
|
consoleMock.mockRestore()
|
|
617
535
|
})
|
|
618
536
|
|
|
619
|
-
it('should not throw errors to the error boundary when
|
|
537
|
+
it('should not throw errors to the error boundary when throwOnError: false', async () => {
|
|
620
538
|
const key = queryKey()
|
|
621
539
|
|
|
622
540
|
function Page() {
|
|
@@ -628,7 +546,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
628
546
|
},
|
|
629
547
|
retry: false,
|
|
630
548
|
suspense: true,
|
|
631
|
-
|
|
549
|
+
throwOnError: false,
|
|
632
550
|
})
|
|
633
551
|
return <div>rendered</div>
|
|
634
552
|
}
|
|
@@ -655,7 +573,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
655
573
|
await waitFor(() => rendered.getByText('rendered'))
|
|
656
574
|
})
|
|
657
575
|
|
|
658
|
-
it('should throw errors to the error boundary when a
|
|
576
|
+
it('should throw errors to the error boundary when a throwOnError function returns true', async () => {
|
|
659
577
|
const consoleMock = vi
|
|
660
578
|
.spyOn(console, 'error')
|
|
661
579
|
.mockImplementation(() => undefined)
|
|
@@ -670,7 +588,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
670
588
|
},
|
|
671
589
|
retry: false,
|
|
672
590
|
suspense: true,
|
|
673
|
-
|
|
591
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
674
592
|
})
|
|
675
593
|
return <div>rendered</div>
|
|
676
594
|
}
|
|
@@ -698,7 +616,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
698
616
|
consoleMock.mockRestore()
|
|
699
617
|
})
|
|
700
618
|
|
|
701
|
-
it('should not throw errors to the error boundary when a
|
|
619
|
+
it('should not throw errors to the error boundary when a throwOnError function returns false', async () => {
|
|
702
620
|
const key = queryKey()
|
|
703
621
|
|
|
704
622
|
function Page() {
|
|
@@ -710,7 +628,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
710
628
|
},
|
|
711
629
|
retry: false,
|
|
712
630
|
suspense: true,
|
|
713
|
-
|
|
631
|
+
throwOnError: (err) => err.message !== 'Local Error',
|
|
714
632
|
})
|
|
715
633
|
return <div>rendered</div>
|
|
716
634
|
}
|
|
@@ -128,33 +128,6 @@ describe('select', () => {
|
|
|
128
128
|
return result
|
|
129
129
|
})
|
|
130
130
|
})
|
|
131
|
-
it('should pass transformed data to onSuccess', () => {
|
|
132
|
-
doNotExecute(() => {
|
|
133
|
-
const infiniteQuery = useInfiniteQuery({
|
|
134
|
-
queryKey: ['key'],
|
|
135
|
-
queryFn: ({ pageParam }) => {
|
|
136
|
-
return pageParam * 5
|
|
137
|
-
},
|
|
138
|
-
defaultPageParam: 1,
|
|
139
|
-
getNextPageParam: () => undefined,
|
|
140
|
-
select: (data) => {
|
|
141
|
-
return {
|
|
142
|
-
...data,
|
|
143
|
-
pages: data.pages.map((page) => page.toString()),
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
onSuccess: (data) => {
|
|
147
|
-
const result: Expect<Equal<InfiniteData<string>, typeof data>> = true
|
|
148
|
-
doNotExecute(() => result)
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
const result: Expect<
|
|
153
|
-
Equal<InfiniteData<string> | undefined, (typeof infiniteQuery)['data']>
|
|
154
|
-
> = true
|
|
155
|
-
return result
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
131
|
})
|
|
159
132
|
describe('getNextPageParam / getPreviousPageParam', () => {
|
|
160
133
|
it('should get typed params', () => {
|
|
@@ -688,7 +688,7 @@ describe('useMutation', () => {
|
|
|
688
688
|
fireEvent.click(getByText('unmount'))
|
|
689
689
|
})
|
|
690
690
|
|
|
691
|
-
it('should be able to throw an error when
|
|
691
|
+
it('should be able to throw an error when throwOnError is set to true', async () => {
|
|
692
692
|
const consoleMock = vi
|
|
693
693
|
.spyOn(console, 'error')
|
|
694
694
|
.mockImplementation(() => undefined)
|
|
@@ -699,7 +699,7 @@ describe('useMutation', () => {
|
|
|
699
699
|
err.stack = ''
|
|
700
700
|
return Promise.reject(err)
|
|
701
701
|
},
|
|
702
|
-
|
|
702
|
+
throwOnError: true,
|
|
703
703
|
})
|
|
704
704
|
|
|
705
705
|
return (
|
|
@@ -735,7 +735,7 @@ describe('useMutation', () => {
|
|
|
735
735
|
consoleMock.mockRestore()
|
|
736
736
|
})
|
|
737
737
|
|
|
738
|
-
it('should be able to throw an error when
|
|
738
|
+
it('should be able to throw an error when throwOnError is a function that returns true', async () => {
|
|
739
739
|
const consoleMock = vi
|
|
740
740
|
.spyOn(console, 'error')
|
|
741
741
|
.mockImplementation(() => undefined)
|
|
@@ -747,7 +747,7 @@ describe('useMutation', () => {
|
|
|
747
747
|
err.stack = ''
|
|
748
748
|
return Promise.reject(err)
|
|
749
749
|
},
|
|
750
|
-
|
|
750
|
+
throwOnError: () => {
|
|
751
751
|
boundary = !boundary
|
|
752
752
|
return !boundary
|
|
753
753
|
},
|
|
@@ -4,10 +4,12 @@ import { useIsMutating, useMutationState } from '../useMutationState'
|
|
|
4
4
|
import { useMutation } from '../useMutation'
|
|
5
5
|
import {
|
|
6
6
|
createQueryClient,
|
|
7
|
+
doNotExecute,
|
|
7
8
|
renderWithClient,
|
|
8
9
|
setActTimeout,
|
|
9
10
|
sleep,
|
|
10
11
|
} from './utils'
|
|
12
|
+
import type { MutationState, MutationStatus } from '@tanstack/query-core'
|
|
11
13
|
|
|
12
14
|
describe('useIsMutating', () => {
|
|
13
15
|
it('should return the number of fetching mutations', async () => {
|
|
@@ -172,6 +174,27 @@ describe('useIsMutating', () => {
|
|
|
172
174
|
})
|
|
173
175
|
|
|
174
176
|
describe('useMutationState', () => {
|
|
177
|
+
describe('types', () => {
|
|
178
|
+
it('should default to QueryState', () => {
|
|
179
|
+
doNotExecute(() => {
|
|
180
|
+
const result = useMutationState({
|
|
181
|
+
filters: { status: 'pending' },
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
expectTypeOf(result).toEqualTypeOf<Array<MutationState>>()
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
it('should infer with select', () => {
|
|
188
|
+
doNotExecute(() => {
|
|
189
|
+
const result = useMutationState({
|
|
190
|
+
filters: { status: 'pending' },
|
|
191
|
+
select: (mutation) => mutation.state.status,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
expectTypeOf(result).toEqualTypeOf<Array<MutationStatus>>()
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
})
|
|
175
198
|
it('should return variables after calling mutate', async () => {
|
|
176
199
|
const queryClient = createQueryClient()
|
|
177
200
|
const variables: unknown[][] = []
|