-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into test/vue-query/use-vitest-d-file
- Loading branch information
Showing
5 changed files
with
101 additions
and
189 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
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
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
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.