|  | 
|  | 1 | +import { useSuspenseQuery } from '../useSuspenseQuery' | 
|  | 2 | +import { useSuspenseInfiniteQuery } from '../useSuspenseInfiniteQuery' | 
|  | 3 | +import { doNotExecute } from './utils' | 
|  | 4 | +import type { InfiniteData } from '@tanstack/query-core' | 
|  | 5 | +import type { Equal, Expect } from './utils' | 
|  | 6 | + | 
|  | 7 | +describe('useSuspenseQuery', () => { | 
|  | 8 | +  it('should always have data defined', () => { | 
|  | 9 | +    doNotExecute(() => { | 
|  | 10 | +      const { data } = useSuspenseQuery({ | 
|  | 11 | +        queryKey: ['key'], | 
|  | 12 | +        queryFn: () => Promise.resolve(5), | 
|  | 13 | +      }) | 
|  | 14 | + | 
|  | 15 | +      const result: Expect<Equal<typeof data, number>> = true | 
|  | 16 | +      return result | 
|  | 17 | +    }) | 
|  | 18 | +  }) | 
|  | 19 | + | 
|  | 20 | +  it('should not have pending status', () => { | 
|  | 21 | +    doNotExecute(() => { | 
|  | 22 | +      const { status } = useSuspenseQuery({ | 
|  | 23 | +        queryKey: ['key'], | 
|  | 24 | +        queryFn: () => Promise.resolve(5), | 
|  | 25 | +      }) | 
|  | 26 | + | 
|  | 27 | +      const result: Expect<Equal<typeof status, 'error' | 'success'>> = true | 
|  | 28 | +      return result | 
|  | 29 | +    }) | 
|  | 30 | +  }) | 
|  | 31 | + | 
|  | 32 | +  it('should not allow placeholderData, enabled or throwOnError props', () => { | 
|  | 33 | +    doNotExecute(() => { | 
|  | 34 | +      useSuspenseQuery({ | 
|  | 35 | +        queryKey: ['key'], | 
|  | 36 | +        queryFn: () => Promise.resolve(5), | 
|  | 37 | +        // @ts-expect-error TS2345 | 
|  | 38 | +        placeholderData: 5, | 
|  | 39 | +        enabled: true, | 
|  | 40 | +      }) | 
|  | 41 | + | 
|  | 42 | +      useSuspenseQuery({ | 
|  | 43 | +        queryKey: ['key'], | 
|  | 44 | +        queryFn: () => Promise.resolve(5), | 
|  | 45 | +        // @ts-expect-error TS2345 | 
|  | 46 | +        enabled: true, | 
|  | 47 | +      }) | 
|  | 48 | + | 
|  | 49 | +      useSuspenseQuery({ | 
|  | 50 | +        queryKey: ['key'], | 
|  | 51 | +        queryFn: () => Promise.resolve(5), | 
|  | 52 | +        // @ts-expect-error TS2345 | 
|  | 53 | +        throwOnError: true, | 
|  | 54 | +      }) | 
|  | 55 | +    }) | 
|  | 56 | +  }) | 
|  | 57 | + | 
|  | 58 | +  it('should not return isPlaceholderData', () => { | 
|  | 59 | +    doNotExecute(() => { | 
|  | 60 | +      const query = useSuspenseQuery({ | 
|  | 61 | +        queryKey: ['key'], | 
|  | 62 | +        queryFn: () => Promise.resolve(5), | 
|  | 63 | +      }) | 
|  | 64 | + | 
|  | 65 | +      // @ts-expect-error TS2339 | 
|  | 66 | +      void query.isPlaceholderData | 
|  | 67 | +    }) | 
|  | 68 | +  }) | 
|  | 69 | +}) | 
|  | 70 | + | 
|  | 71 | +describe('useSuspenseInfiniteQuery', () => { | 
|  | 72 | +  it('should always have data defined', () => { | 
|  | 73 | +    doNotExecute(() => { | 
|  | 74 | +      const { data } = useSuspenseInfiniteQuery({ | 
|  | 75 | +        queryKey: ['key'], | 
|  | 76 | +        queryFn: () => Promise.resolve(5), | 
|  | 77 | +        initialPageParam: 1, | 
|  | 78 | +        getNextPageParam: () => 1, | 
|  | 79 | +      }) | 
|  | 80 | + | 
|  | 81 | +      const result: Expect<Equal<typeof data, InfiniteData<number, unknown>>> = | 
|  | 82 | +        true | 
|  | 83 | +      return result | 
|  | 84 | +    }) | 
|  | 85 | +  }) | 
|  | 86 | + | 
|  | 87 | +  it('should not have pending status', () => { | 
|  | 88 | +    doNotExecute(() => { | 
|  | 89 | +      const { status } = useSuspenseInfiniteQuery({ | 
|  | 90 | +        queryKey: ['key'], | 
|  | 91 | +        queryFn: () => Promise.resolve(5), | 
|  | 92 | +        initialPageParam: 1, | 
|  | 93 | +        getNextPageParam: () => 1, | 
|  | 94 | +      }) | 
|  | 95 | + | 
|  | 96 | +      const result: Expect<Equal<typeof status, 'error' | 'success'>> = true | 
|  | 97 | +      return result | 
|  | 98 | +    }) | 
|  | 99 | +  }) | 
|  | 100 | + | 
|  | 101 | +  it('should not allow placeholderData, enabled or throwOnError props', () => { | 
|  | 102 | +    doNotExecute(() => { | 
|  | 103 | +      useSuspenseInfiniteQuery({ | 
|  | 104 | +        queryKey: ['key'], | 
|  | 105 | +        queryFn: () => Promise.resolve(5), | 
|  | 106 | +        initialPageParam: 1, | 
|  | 107 | +        getNextPageParam: () => 1, | 
|  | 108 | +        // @ts-expect-error TS2345 | 
|  | 109 | +        placeholderData: 5, | 
|  | 110 | +        enabled: true, | 
|  | 111 | +      }) | 
|  | 112 | + | 
|  | 113 | +      useSuspenseInfiniteQuery({ | 
|  | 114 | +        queryKey: ['key'], | 
|  | 115 | +        queryFn: () => Promise.resolve(5), | 
|  | 116 | +        initialPageParam: 1, | 
|  | 117 | +        getNextPageParam: () => 1, | 
|  | 118 | +        // @ts-expect-error TS2345 | 
|  | 119 | +        enabled: true, | 
|  | 120 | +      }) | 
|  | 121 | + | 
|  | 122 | +      useSuspenseInfiniteQuery({ | 
|  | 123 | +        queryKey: ['key'], | 
|  | 124 | +        queryFn: () => Promise.resolve(5), | 
|  | 125 | +        initialPageParam: 1, | 
|  | 126 | +        getNextPageParam: () => 1, | 
|  | 127 | +        // @ts-expect-error TS2345 | 
|  | 128 | +        throwOnError: true, | 
|  | 129 | +      }) | 
|  | 130 | +    }) | 
|  | 131 | +  }) | 
|  | 132 | + | 
|  | 133 | +  it('should not return isPlaceholderData', () => { | 
|  | 134 | +    doNotExecute(() => { | 
|  | 135 | +      const query = useSuspenseInfiniteQuery({ | 
|  | 136 | +        queryKey: ['key'], | 
|  | 137 | +        queryFn: () => Promise.resolve(5), | 
|  | 138 | +        initialPageParam: 1, | 
|  | 139 | +        getNextPageParam: () => 1, | 
|  | 140 | +      }) | 
|  | 141 | + | 
|  | 142 | +      // @ts-expect-error TS2339 | 
|  | 143 | +      void query.isPlaceholderData | 
|  | 144 | +    }) | 
|  | 145 | +  }) | 
|  | 146 | +}) | 
0 commit comments