-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(solid-query): use vitest typecheck correctly with *.test-d.ts (#…
- Loading branch information
Showing
2 changed files
with
98 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { describe, expectTypeOf, it } from 'vitest' | ||
import { createQuery, queryOptions } from '../index' | ||
|
||
describe('initialData', () => { | ||
describe('Config object overload', () => { | ||
it('TData should always be defined when initialData is provided as an object', () => { | ||
const { data } = createQuery(() => ({ | ||
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 } = createQuery(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 } = createQuery(() => ({ | ||
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 } = createQuery(() => ({ | ||
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 } = createQuery(() => ({ | ||
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 } = createQuery(() => ({ | ||
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 } = createQuery(() => ({ | ||
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 } = createQuery(() => ({ | ||
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 } = createQuery(() => ({ | ||
queryKey: ['key'], | ||
queryFn: () => ({ wow: true }), | ||
})) | ||
|
||
expectTypeOf(data).toEqualTypeOf<{ wow: boolean } | undefined>() | ||
}) | ||
}) | ||
}) |
186 changes: 0 additions & 186 deletions
186
packages/solid-query/src/__tests__/createQuery.types.test.tsx
This file was deleted.
Oops, something went wrong.