Skip to content

Commit

Permalink
Merge branch 'main' into test/vue-query/use-vitest-d-file
Browse files Browse the repository at this point in the history
  • Loading branch information
manudeli authored Mar 3, 2024
2 parents f454c08 + b311a0a commit c1b912d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 189 deletions.
2 changes: 1 addition & 1 deletion docs/framework/react/guides/advanced-ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function getQueryClient() {
} else {
// Browser: make a new query client if we don't already have one
// This is very important so we don't re-make a new client if React
// supsends during the initial render. This may not be needed if we
// suspends during the initial render. This may not be needed if we
// have a suspense boundary BELOW the creation of the query client
if (!browserQueryClient) browserQueryClient = makeQueryClient()
return browserQueryClient
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/guides/prefetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Infinite Queries can be prefetched like regular Queries. Per default, only the f
[//]: # 'ExamplePrefetchInfiniteQuery'

```tsx
const prefetchTodos = async () => {
const prefetchProjects = async () => {
// The results of this query will be cached like a normal query
await queryClient.prefetchInfiniteQuery({
queryKey: ['projects'],
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/vue/guides/prefetching.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Infinite Queries can be prefetched like regular Queries. Per default, only the f
[//]: # 'ExampleInfiniteQuery'

```tsx
const prefetchTodos = async () => {
const prefetchProjects = async () => {
// The results of this query will be cached like a normal query
await queryClient.prefetchInfiniteQuery({
queryKey: ['projects'],
Expand Down
98 changes: 98 additions & 0 deletions packages/solid-query/src/__tests__/createQuery.test-d.tsx
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 packages/solid-query/src/__tests__/createQuery.types.test.tsx

This file was deleted.

0 comments on commit c1b912d

Please sign in to comment.