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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { render } from '@testing-library/svelte'
import { sleep } from '@tanstack/query-test-utils'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { QueryClient, createQueries } from '../../src/index.js'
import { promiseWithResolvers, withEffectRoot } from '../utils.svelte.js'
import IsRestoringExample from './IsRestoringExample.svelte'
Expand All @@ -22,8 +22,8 @@ describe('createQueries', () => {
it(
'should return the correct states',
withEffectRoot(async () => {
const key1 = ['test-1']
const key2 = ['test-2']
const key1 = queryKey()
const key2 = queryKey()
const results: Array<Array<CreateQueryResult>> = []
const { promise: promise1, resolve: resolve1 } = promiseWithResolvers()
const { promise: promise2, resolve: resolve2 } = promiseWithResolvers()
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('createQueries', () => {
it(
'should track results',
withEffectRoot(async () => {
const key1 = ['test-track-results']
const key1 = queryKey()
const results: Array<Array<CreateQueryResult>> = []
let count = 0

Expand Down Expand Up @@ -111,8 +111,8 @@ describe('createQueries', () => {
it(
'should combine queries',
withEffectRoot(async () => {
const key1 = ['test-combine-1']
const key2 = ['test-combine-2']
const key1 = queryKey()
const key2 = queryKey()

const { promise: promise1, resolve: resolve1 } =
promiseWithResolvers<string>()
Expand Down Expand Up @@ -169,8 +169,8 @@ describe('createQueries', () => {
it(
'should track property access through combine function',
withEffectRoot(async () => {
const key1 = ['test-track-combine-1']
const key2 = ['test-track-combine-2']
const key1 = queryKey()
const key2 = queryKey()
let count = 0
const results: Array<unknown> = []

Expand Down
27 changes: 15 additions & 12 deletions packages/svelte-query/tests/createQueries/createQueries.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expectTypeOf, it } from 'vitest'
import { QueryClient } from '@tanstack/query-core'
import { queryKey } from '@tanstack/query-test-utils'
import { createQueries, queryOptions } from '../../src/index.js'
import type {
CreateQueryOptions,
Expand All @@ -12,17 +13,19 @@ import type {

describe('createQueries', () => {
it('should return correct data for dynamic queries with mixed result types', () => {
const key1 = queryKey()
const key2 = queryKey()
const Queries1 = {
get: () =>
queryOptions({
queryKey: ['key1'],
queryKey: key1,
queryFn: () => Promise.resolve(1),
}),
}
const Queries2 = {
get: () =>
queryOptions({
queryKey: ['key2'],
queryKey: key2,
queryFn: () => Promise.resolve(true),
}),
}
Expand All @@ -42,9 +45,9 @@ describe('createQueries', () => {

it('handles type parameter - tuple of tuples', () => {
const queryClient = new QueryClient()
const key1 = ['test-key-1']
const key2 = ['test-key-2']
const key3 = ['test-key-3']
const key1 = queryKey()
const key2 = queryKey()
const key3 = queryKey()

const result1 = createQueries<
[[number], [string], [Array<string>, boolean]]
Expand Down Expand Up @@ -157,9 +160,9 @@ describe('createQueries', () => {

it('handles type parameter - tuple of objects', () => {
const queryClient = new QueryClient()
const key1 = ['test-key-1']
const key2 = ['test-key-2']
const key3 = ['test-key-3']
const key1 = queryKey()
const key2 = queryKey()
const key3 = queryKey()

const result1 = createQueries<
[
Expand Down Expand Up @@ -314,10 +317,10 @@ describe('createQueries', () => {

it('handles array literal without type parameter to infer result type', () => {
const queryClient = new QueryClient()
const key1 = ['test-key-1']
const key2 = ['test-key-2']
const key3 = ['test-key-3']
const key4 = ['test-key-4']
const key1 = queryKey()
const key2 = queryKey()
const key3 = queryKey()
const key4 = queryKey()

// Array.map preserves TQueryFnData
const result1 = createQueries(
Expand Down
Loading
Loading