Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/solid-query/src/__tests__/createQueries.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expectTypeOf, it } from 'vitest'
import { queryKey } from '@tanstack/query-test-utils'
import { queryOptions, useQueries } from '..'
import type { UseQueryResult } from '..'

Expand All @@ -7,14 +8,14 @@ describe('useQueries', () => {
const Queries1 = {
get: () =>
queryOptions({
queryKey: ['key1'],
queryKey: queryKey(),
queryFn: () => Promise.resolve(1),
}),
}
const Queries2 = {
get: () =>
queryOptions({
queryKey: ['key2'],
queryKey: queryKey(),
queryFn: () => Promise.resolve(true),
}),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expectTypeOf, it } from 'vitest'
import { dataTagSymbol } from '@tanstack/query-core'
import { queryKey } from '@tanstack/query-test-utils'
import { useInfiniteQuery } from '../useInfiniteQuery'
import { infiniteQueryOptions } from '../infiniteQueryOptions'
import type { InfiniteData } from '@tanstack/query-core'
Expand All @@ -12,7 +13,7 @@ describe('infiniteQueryOptions', () => {
it('should infer defined types', () => {
const options = infiniteQueryOptions({
getNextPageParam: () => 10,
queryKey: ['key'],
queryKey: queryKey(),
queryFn: () => ({ wow: true }),
initialData: {
pageParams: [undefined],
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('infiniteQueryOptions', () => {
it('should work without defined types', () => {
const options = infiniteQueryOptions({
getNextPageParam: () => undefined,
queryKey: ['key'],
queryKey: queryKey(),
queryFn: () => ({ wow: true }),
initialPageParam: 0,
})
Expand Down
23 changes: 12 additions & 11 deletions packages/solid-query/src/__tests__/mutationOptions.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertType, describe, expectTypeOf, it } from 'vitest'
import { QueryClient } from '@tanstack/query-core'
import { queryKey } from '@tanstack/query-test-utils'
import { useIsMutating, useMutation, useMutationState } from '..'
import { mutationOptions } from '../mutationOptions'
import type {
Expand All @@ -15,7 +16,7 @@ describe('mutationOptions', () => {
// @ts-expect-error this is a good error, because onMutates does not exist!
mutationOptions({
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
mutationKey: queryKey(),
onMutates: 1000,
onSuccess: (data) => {
expectTypeOf(data).toEqualTypeOf<number>()
Expand All @@ -26,7 +27,7 @@ describe('mutationOptions', () => {
it('should infer types for callbacks', () => {
mutationOptions({
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
mutationKey: queryKey(),
onSuccess: (data) => {
expectTypeOf(data).toEqualTypeOf<number>()
},
Expand All @@ -38,7 +39,7 @@ describe('mutationOptions', () => {
mutationFn: () => {
throw new Error('fail')
},
mutationKey: ['key'],
mutationKey: queryKey(),
onError: (error) => {
expectTypeOf(error).toEqualTypeOf<DefaultError>()
},
Expand All @@ -51,14 +52,14 @@ describe('mutationOptions', () => {
expectTypeOf(vars).toEqualTypeOf<{ id: string }>()
return Promise.resolve(5)
},
mutationKey: ['with-vars'],
mutationKey: queryKey(),
})
})

it('should infer result type correctly', () => {
mutationOptions<number, DefaultError, void, { name: string }>({
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
mutationKey: queryKey(),
onMutate: () => {
return { name: 'onMutateResult' }
},
Expand All @@ -74,7 +75,7 @@ describe('mutationOptions', () => {
expectTypeOf(context).toEqualTypeOf<MutationFunctionContext>()
return Promise.resolve(5)
},
mutationKey: ['key'],
mutationKey: queryKey(),
onMutate: (_variables, context) => {
expectTypeOf(context).toEqualTypeOf<MutationFunctionContext>()
},
Expand Down Expand Up @@ -112,7 +113,7 @@ describe('mutationOptions', () => {
expectTypeOf(
mutationOptions({
mutationFn: (id: string) => Promise.resolve(id.length),
mutationKey: ['key'],
mutationKey: queryKey(),
onSuccess: (data) => {
expectTypeOf(data).toEqualTypeOf<number>()
},
Expand All @@ -138,7 +139,7 @@ describe('mutationOptions', () => {
it('should infer types when used with useMutation', () => {
const mutation = useMutation(() =>
mutationOptions({
mutationKey: ['key'],
mutationKey: queryKey(),
mutationFn: () => Promise.resolve('data'),
onSuccess: (data) => {
expectTypeOf(data).toEqualTypeOf<string>()
Expand All @@ -163,7 +164,7 @@ describe('mutationOptions', () => {
it('should infer types when used with useIsMutating', () => {
const isMutating = useIsMutating(() =>
mutationOptions({
mutationKey: ['key'],
mutationKey: queryKey(),
mutationFn: () => Promise.resolve(5),
}),
)
Expand All @@ -183,7 +184,7 @@ describe('mutationOptions', () => {

const isMutating = queryClient.isMutating(
mutationOptions({
mutationKey: ['key'],
mutationKey: queryKey(),
mutationFn: () => Promise.resolve(5),
}),
)
Expand All @@ -200,7 +201,7 @@ describe('mutationOptions', () => {
it('should infer types when used with useMutationState', () => {
const mutationState = useMutationState(() => ({
filters: mutationOptions({
mutationKey: ['key'],
mutationKey: queryKey(),
mutationFn: () => Promise.resolve(5),
}),
}))
Expand Down
29 changes: 19 additions & 10 deletions packages/solid-query/src/__tests__/mutationOptions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { fireEvent, render } from '@solidjs/testing-library'
import { createEffect, createRenderEffect } from 'solid-js'
import { sleep } from '@tanstack/query-test-utils'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import {
QueryClient,
QueryClientProvider,
Expand Down Expand Up @@ -41,8 +41,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with useIsMutating (with mutationKey in mutationOptions)', async () => {
const isMutatingArray: Array<number> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts = mutationOptions({
mutationKey: ['key'],
mutationKey: key,
mutationFn: () => sleep(50).then(() => 'data'),
})

Expand Down Expand Up @@ -116,8 +117,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with useIsMutating', async () => {
const isMutatingArray: Array<number> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts1 = mutationOptions({
mutationKey: ['key'],
mutationKey: key,
mutationFn: () => sleep(50).then(() => 'data1'),
})
const mutationOpts2 = mutationOptions({
Expand Down Expand Up @@ -159,8 +161,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with useIsMutating (filter mutationOpts1.mutationKey)', async () => {
const isMutatingArray: Array<number> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts1 = mutationOptions({
mutationKey: ['key'],
mutationKey: key,
mutationFn: () => sleep(50).then(() => 'data1'),
})
const mutationOpts2 = mutationOptions({
Expand Down Expand Up @@ -205,8 +208,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with queryClient.isMutating (with mutationKey in mutationOptions)', async () => {
const isMutatingArray: Array<number> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts = mutationOptions({
mutationKey: ['mutation'],
mutationKey: key,
mutationFn: () => sleep(500).then(() => 'data'),
})

Expand Down Expand Up @@ -288,8 +292,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with queryClient.isMutating', async () => {
const isMutatingArray: Array<number> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts1 = mutationOptions({
mutationKey: ['mutation'],
mutationKey: key,
mutationFn: () => sleep(500).then(() => 'data1'),
})
const mutationOpts2 = mutationOptions({
Expand Down Expand Up @@ -336,8 +341,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with queryClient.isMutating (filter mutationOpt1.mutationKey)', async () => {
const isMutatingArray: Array<number> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts1 = mutationOptions({
mutationKey: ['mutation'],
mutationKey: key,
mutationFn: () => sleep(500).then(() => 'data1'),
})
const mutationOpts2 = mutationOptions({
Expand Down Expand Up @@ -392,8 +398,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with useMutationState (with mutationKey in mutationOptions)', async () => {
const mutationStateArray: Array<Array<MutationState>> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts = mutationOptions({
mutationKey: ['mutation'],
mutationKey: key,
mutationFn: () => sleep(10).then(() => 'data'),
})

Expand Down Expand Up @@ -471,8 +478,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with useMutationState', async () => {
const mutationStateArray: Array<Array<MutationState>> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts1 = mutationOptions({
mutationKey: ['mutation'],
mutationKey: key,
mutationFn: () => sleep(10).then(() => 'data1'),
})
const mutationOpts2 = mutationOptions({
Expand Down Expand Up @@ -518,8 +526,9 @@ describe('mutationOptions', () => {
it('should return the number of fetching mutations when used with useMutationState (filter mutationOpt1.mutationKey)', async () => {
const mutationStateArray: Array<Array<MutationState>> = []
const queryClient = new QueryClient()
const key = queryKey()
const mutationOpts1 = mutationOptions({
mutationKey: ['mutation'],
mutationKey: key,
mutationFn: () => sleep(10).then(() => 'data1'),
})
const mutationOpts2 = mutationOptions({
Expand Down
Loading
Loading