Download react-query/packages/solid-query/src/__tests__/useQuery.test-d.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.15 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/solid-query/src/__tests__/useQuery.test-d.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/solid-query/src/__tests__/useQuery.test-d.tsx
-
curl -L -o useQuery.test-d.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/solid-query/src/__tests__/useQuery.test-d.tsx
3.15 kB
| import { describe, expectTypeOf, it } from 'vitest' | |
| import { queryOptions, useQuery } from '../index' | |
| describe('initialData', () => { | |
| describe('Config object overload', () => { | |
| it('TData should always be defined when initialData is provided as an object', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| initialData: { wow: true }, | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() | |
| }) | |
| it('TData should be defined when passed through queryOptions', () => { | |
| const options = queryOptions({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| initialData: { wow: true }, | |
| }) | |
| const { data } = useQuery(() => options) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() | |
| }) | |
| it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| initialData: () => ({ wow: true }), | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() | |
| }) | |
| it('TData should have undefined in the union when initialData is NOT provided', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() | |
| }) | |
| it('TData should have undefined in the union when initialData is provided as a function which can return undefined', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| initialData: () => undefined as { wow: boolean } | undefined, | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() | |
| }) | |
| }) | |
| describe('Query key overload', () => { | |
| it('TData should always be defined when initialData is provided', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| initialData: { wow: true }, | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() | |
| }) | |
| it('TData should have undefined in the union when initialData is NOT provided', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() | |
| }) | |
| }) | |
| describe('Query key and func', () => { | |
| it('TData should always be defined when initialData is provided', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| initialData: { wow: true }, | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean }>() | |
| }) | |
| it('TData should have undefined in the union when initialData is NOT provided', () => { | |
| const { data } = useQuery(() => ({ | |
| queryKey: ['key'], | |
| queryFn: () => ({ wow: true }), | |
| })) | |
| expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() | |
| }) | |
| }) | |
| }) | |