@tanstack/query-core 5.59.17 → 5.59.20

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.
@@ -1,108 +0,0 @@
1
- import { afterEach, beforeEach, describe, expectTypeOf, it } from 'vitest'
2
- import { QueryObserver } from '..'
3
- import { createQueryClient, queryKey } from './utils'
4
- import type { QueryClient } from '..'
5
-
6
- describe('queryObserver', () => {
7
- let queryClient: QueryClient
8
-
9
- beforeEach(() => {
10
- queryClient = createQueryClient()
11
- queryClient.mount()
12
- })
13
-
14
- afterEach(() => {
15
- queryClient.clear()
16
- })
17
-
18
- it('should be inferred as a correct result type', () => {
19
- const observer = new QueryObserver(queryClient, {
20
- queryKey: queryKey(),
21
- queryFn: () => Promise.resolve({ value: 'data' }),
22
- })
23
-
24
- const result = observer.getCurrentResult()
25
-
26
- if (result.isPending) {
27
- expectTypeOf(result.data).toEqualTypeOf<undefined>()
28
- expectTypeOf(result.error).toEqualTypeOf<null>()
29
- expectTypeOf(result.isLoading).toEqualTypeOf<boolean>()
30
- expectTypeOf(result.status).toEqualTypeOf<'pending'>()
31
- }
32
- if (result.isLoading) {
33
- expectTypeOf(result.data).toEqualTypeOf<undefined>()
34
- expectTypeOf(result.error).toEqualTypeOf<null>()
35
- expectTypeOf(result.isPending).toEqualTypeOf<true>()
36
- expectTypeOf(result.status).toEqualTypeOf<'pending'>()
37
- }
38
-
39
- if (result.isLoadingError) {
40
- expectTypeOf(result.data).toEqualTypeOf<undefined>()
41
- expectTypeOf(result.error).toEqualTypeOf<Error>()
42
- expectTypeOf(result.status).toEqualTypeOf<'error'>()
43
- }
44
-
45
- if (result.isRefetchError) {
46
- expectTypeOf(result.data).toEqualTypeOf<{ value: string }>()
47
- expectTypeOf(result.error).toEqualTypeOf<Error>()
48
- expectTypeOf(result.status).toEqualTypeOf<'error'>()
49
- }
50
-
51
- if (result.isSuccess) {
52
- expectTypeOf(result.data).toEqualTypeOf<{ value: string }>()
53
- expectTypeOf(result.error).toEqualTypeOf<null>()
54
- expectTypeOf(result.status).toEqualTypeOf<'success'>()
55
- }
56
- })
57
-
58
- describe('placeholderData', () => {
59
- it('previousQuery should have typed queryKey', () => {
60
- const testQueryKey = ['SomeQuery', 42, { foo: 'bar' }] as const
61
-
62
- new QueryObserver(createQueryClient(), {
63
- queryKey: testQueryKey,
64
- placeholderData: (_, previousQuery) => {
65
- if (previousQuery) {
66
- expectTypeOf(previousQuery.queryKey).toEqualTypeOf<
67
- typeof testQueryKey
68
- >()
69
- }
70
- },
71
- })
72
- })
73
-
74
- it('previousQuery should have typed error', () => {
75
- class CustomError extends Error {
76
- name = 'CustomError' as const
77
- }
78
-
79
- new QueryObserver<boolean, CustomError>(createQueryClient(), {
80
- queryKey: ['key'],
81
- placeholderData: (_, previousQuery) => {
82
- if (previousQuery) {
83
- expectTypeOf(
84
- previousQuery.state.error,
85
- ).toEqualTypeOf<CustomError | null>()
86
- }
87
- return undefined
88
- },
89
- })
90
- })
91
-
92
- it('previousData should have the same type as query data', () => {
93
- const queryData = { foo: 'bar' } as const
94
-
95
- new QueryObserver(createQueryClient(), {
96
- queryKey: ['key'],
97
- queryFn: () => queryData,
98
- select: (data) => data.foo,
99
- placeholderData: (previousData) => {
100
- expectTypeOf(previousData).toEqualTypeOf<
101
- typeof queryData | undefined
102
- >()
103
- return undefined
104
- },
105
- })
106
- })
107
- })
108
- })