diff --git a/packages/svelte-query-persist-client/tests/AwaitOnSuccess/AwaitOnSuccess.svelte b/packages/svelte-query-persist-client/tests/AwaitOnSuccess/AwaitOnSuccess.svelte index a219a4d99f..cf8764a015 100644 --- a/packages/svelte-query-persist-client/tests/AwaitOnSuccess/AwaitOnSuccess.svelte +++ b/packages/svelte-query-persist-client/tests/AwaitOnSuccess/AwaitOnSuccess.svelte @@ -1,9 +1,8 @@ - + diff --git a/packages/svelte-query-persist-client/tests/FreshData/FreshData.svelte b/packages/svelte-query-persist-client/tests/FreshData/FreshData.svelte index 33f1abcf13..790126d48f 100644 --- a/packages/svelte-query-persist-client/tests/FreshData/FreshData.svelte +++ b/packages/svelte-query-persist-client/tests/FreshData/FreshData.svelte @@ -1,22 +1,22 @@ diff --git a/packages/svelte-query-persist-client/tests/FreshData/Provider.svelte b/packages/svelte-query-persist-client/tests/FreshData/Provider.svelte index 835011ae02..657b1aea3f 100644 --- a/packages/svelte-query-persist-client/tests/FreshData/Provider.svelte +++ b/packages/svelte-query-persist-client/tests/FreshData/Provider.svelte @@ -3,13 +3,13 @@ import FreshData from './FreshData.svelte' import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query' import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core' - import type { StatusResult } from '../utils' + import type { StatusResult } from '../utils.svelte' interface Props { queryClient: QueryClient persistOptions: OmitKeyof key: Array - states: Array> + states: { value: Array> } fetched: boolean } diff --git a/packages/svelte-query-persist-client/tests/InitialData/InitialData.svelte b/packages/svelte-query-persist-client/tests/InitialData/InitialData.svelte index 17824587ca..3716a08b11 100644 --- a/packages/svelte-query-persist-client/tests/InitialData/InitialData.svelte +++ b/packages/svelte-query-persist-client/tests/InitialData/InitialData.svelte @@ -1,15 +1,15 @@ diff --git a/packages/svelte-query-persist-client/tests/InitialData/Provider.svelte b/packages/svelte-query-persist-client/tests/InitialData/Provider.svelte index 37f9644134..51250ac5dc 100644 --- a/packages/svelte-query-persist-client/tests/InitialData/Provider.svelte +++ b/packages/svelte-query-persist-client/tests/InitialData/Provider.svelte @@ -3,23 +3,18 @@ import InitialData from './InitialData.svelte' import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query' import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core' - import type { StatusResult } from '../utils' + import type { StatusResult } from '../utils.svelte' interface Props { queryClient: QueryClient persistOptions: OmitKeyof key: Array - states: Array> + states: { value: Array> } } - let { - queryClient, - persistOptions, - key, - states = $bindable(), - }: Props = $props() + let { queryClient, persistOptions, key, states }: Props = $props() - + diff --git a/packages/svelte-query-persist-client/tests/OnSuccess/OnSuccess.svelte b/packages/svelte-query-persist-client/tests/OnSuccess/OnSuccess.svelte index 8bd6f0240c..f1e5a81421 100644 --- a/packages/svelte-query-persist-client/tests/OnSuccess/OnSuccess.svelte +++ b/packages/svelte-query-persist-client/tests/OnSuccess/OnSuccess.svelte @@ -1,6 +1,6 @@ - + diff --git a/packages/svelte-query-persist-client/tests/RestoreCache/RestoreCache.svelte b/packages/svelte-query-persist-client/tests/RestoreCache/RestoreCache.svelte index 0701f6f9f6..876541bc3f 100644 --- a/packages/svelte-query-persist-client/tests/RestoreCache/RestoreCache.svelte +++ b/packages/svelte-query-persist-client/tests/RestoreCache/RestoreCache.svelte @@ -1,18 +1,18 @@
-

{ss.data}

-

fetchStatus: {ss.fetchStatus}

+

{query.data}

+

fetchStatus: {query.fetchStatus}

diff --git a/packages/svelte-query-persist-client/tests/UseQueries/Provider.svelte b/packages/svelte-query-persist-client/tests/UseQueries/Provider.svelte index f9e1922f35..06e67de7d7 100644 --- a/packages/svelte-query-persist-client/tests/UseQueries/Provider.svelte +++ b/packages/svelte-query-persist-client/tests/UseQueries/Provider.svelte @@ -3,21 +3,16 @@ import UseQueries from './UseQueries.svelte' import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query' import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core' - import type { StatusResult } from '../utils' + import type { StatusResult } from '../utils.svelte' interface Props { queryClient: QueryClient persistOptions: OmitKeyof key: Array - states: Array> + states: { value: Array> } } - let { - queryClient, - persistOptions, - key, - states = $bindable(), - }: Props = $props() + let { queryClient, persistOptions, key, states }: Props = $props() diff --git a/packages/svelte-query-persist-client/tests/UseQueries/UseQueries.svelte b/packages/svelte-query-persist-client/tests/UseQueries/UseQueries.svelte index 02f86831fd..d603acefdd 100644 --- a/packages/svelte-query-persist-client/tests/UseQueries/UseQueries.svelte +++ b/packages/svelte-query-persist-client/tests/UseQueries/UseQueries.svelte @@ -1,15 +1,15 @@ diff --git a/packages/svelte-query-persist-client/tests/utils.ts b/packages/svelte-query-persist-client/tests/utils.svelte.ts similarity index 76% rename from packages/svelte-query-persist-client/tests/utils.ts rename to packages/svelte-query-persist-client/tests/utils.svelte.ts index c02d3110a0..2518fee2d1 100644 --- a/packages/svelte-query-persist-client/tests/utils.ts +++ b/packages/svelte-query-persist-client/tests/utils.svelte.ts @@ -23,3 +23,16 @@ export type StatusResult = { fetchStatus: string data: T | undefined } + +export function ref(initial: T) { + let value = $state(initial) + + return { + get value() { + return value + }, + set value(newValue) { + value = newValue + }, + } +} diff --git a/packages/svelte-query-persist-client/vite.config.ts b/packages/svelte-query-persist-client/vite.config.ts index af34d9a112..3f68d52480 100644 --- a/packages/svelte-query-persist-client/vite.config.ts +++ b/packages/svelte-query-persist-client/vite.config.ts @@ -9,7 +9,6 @@ export default defineConfig({ name: packageJson.name, dir: './tests', watch: false, - include: ['**/*.svelte.ts'], environment: 'jsdom', setupFiles: ['./tests/test-setup.ts'], coverage: { enabled: true, provider: 'istanbul', include: ['src/**/*'] }, diff --git a/packages/svelte-query/tests/QueryClientProvider/ChildComponent.svelte b/packages/svelte-query/tests/QueryClientProvider/ChildComponent.svelte index fde5ed6fb1..7cebabec0f 100644 --- a/packages/svelte-query/tests/QueryClientProvider/ChildComponent.svelte +++ b/packages/svelte-query/tests/QueryClientProvider/ChildComponent.svelte @@ -1,6 +1,6 @@ diff --git a/packages/svelte-query/tests/createQuery/DisabledExample.svelte b/packages/svelte-query/tests/createQuery/DisabledExample.svelte index faac99c118..4eba0fb0a3 100644 --- a/packages/svelte-query/tests/createQuery/DisabledExample.svelte +++ b/packages/svelte-query/tests/createQuery/DisabledExample.svelte @@ -1,7 +1,7 @@ diff --git a/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts b/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts index 7f4bc1be86..ef9f95ca91 100644 --- a/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts +++ b/packages/svelte-query/tests/createQuery/createQuery.svelte.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from 'vitest' import { fireEvent, render, waitFor } from '@testing-library/svelte' import { QueryClient } from '@tanstack/query-core' -import { sleep } from '../utils' +import { ref, sleep } from '../utils.svelte' import BaseExample from './BaseExample.svelte' import DisabledExample from './DisabledExample.svelte' import PlaceholderData from './PlaceholderData.svelte' @@ -9,7 +9,7 @@ import type { QueryObserverResult } from '@tanstack/query-core' describe('createQuery', () => { test('Return the correct states for a successful query', async () => { - let states: Array = $state([]) + let states = ref>([]) const options = { queryKey: ['test'], @@ -31,9 +31,9 @@ describe('createQuery', () => { expect(rendered.queryByText('Success')).toBeInTheDocument() }) - expect(states).toHaveLength(2) + expect(states.value).toHaveLength(2) - expect(states[0]).toMatchObject({ + expect(states.value[0]).toMatchObject({ data: undefined, dataUpdatedAt: 0, error: null, @@ -60,7 +60,7 @@ describe('createQuery', () => { fetchStatus: 'fetching', }) - expect(states[1]).toMatchObject({ + expect(states.value[1]).toMatchObject({ data: 'Success', dataUpdatedAt: expect.any(Number), error: null, @@ -89,7 +89,7 @@ describe('createQuery', () => { }) test('Return the correct states for an unsuccessful query', async () => { - const states: Array = $state([]) + let states = ref>([]) const options = { queryKey: ['test'], @@ -108,9 +108,9 @@ describe('createQuery', () => { await waitFor(() => rendered.getByText('Status: error')) - expect(states).toHaveLength(3) + expect(states.value).toHaveLength(3) - expect(states[0]).toMatchObject({ + expect(states.value[0]).toMatchObject({ data: undefined, dataUpdatedAt: 0, error: null, @@ -137,7 +137,7 @@ describe('createQuery', () => { fetchStatus: 'fetching', }) - expect(states[1]).toMatchObject({ + expect(states.value[1]).toMatchObject({ data: undefined, dataUpdatedAt: 0, error: null, @@ -164,7 +164,7 @@ describe('createQuery', () => { fetchStatus: 'fetching', }) - expect(states[2]).toMatchObject({ + expect(states.value[2]).toMatchObject({ data: undefined, dataUpdatedAt: 0, error: new Error('Rejected'), @@ -193,7 +193,7 @@ describe('createQuery', () => { }) test('Accept a writable store for options', async () => { - const statesStore: Array = $state([]) + let states = ref>([]) const optionsStore = $state({ queryKey: ['test'], @@ -207,7 +207,7 @@ describe('createQuery', () => { props: { options: optionsStore, queryClient: new QueryClient(), - states: statesStore, + states, }, }) @@ -217,7 +217,7 @@ describe('createQuery', () => { }) test('Accept a derived store for options', async () => { - const states: Array = $state([]) + let states = ref>([]) const writableStore = $state('test') @@ -243,7 +243,7 @@ describe('createQuery', () => { }) test('Ensure reactivity when queryClient defaults are set', async () => { - const states: Array = $state([]) + let states = ref>([]) let writableStore = $state(1) @@ -286,7 +286,7 @@ describe('createQuery', () => { }) test('Keep previous data when placeholderData is set', async () => { - const states: Array = $state([]) + let states = ref>([]) const rendered = render(PlaceholderData, { props: { @@ -301,31 +301,31 @@ describe('createQuery', () => { await waitFor(() => rendered.getByText('Data: 1')) - expect(states).toHaveLength(4) + expect(states.value).toHaveLength(4) // Initial - expect(states[0]).toMatchObject({ + expect(states.value[0]).toMatchObject({ data: undefined, isFetching: true, isSuccess: false, isPlaceholderData: false, }) // Fetched - expect(states[1]).toMatchObject({ + expect(states.value[1]).toMatchObject({ data: 0, isFetching: false, isSuccess: true, isPlaceholderData: false, }) // Set state - expect(states[2]).toMatchObject({ + expect(states.value[2]).toMatchObject({ data: 0, isFetching: true, isSuccess: true, isPlaceholderData: true, }) // New data - expect(states[3]).toMatchObject({ + expect(states.value[3]).toMatchObject({ data: 1, isFetching: false, isSuccess: true, diff --git a/packages/svelte-query/tests/useIsFetching/BaseExample.svelte b/packages/svelte-query/tests/useIsFetching/BaseExample.svelte index 3db0c5bf6e..7307e263c7 100644 --- a/packages/svelte-query/tests/useIsFetching/BaseExample.svelte +++ b/packages/svelte-query/tests/useIsFetching/BaseExample.svelte @@ -2,7 +2,7 @@ import { QueryClient } from '@tanstack/query-core' import { createQuery } from '../../src/' import { useIsFetching } from '../../src/useIsFetching.svelte' - import { queryKey, sleep } from '../utils' + import { queryKey, sleep } from '../utils.svelte' const queryClient = new QueryClient() const key = queryKey() diff --git a/packages/svelte-query/tests/useIsMutating/BaseExample.svelte b/packages/svelte-query/tests/useIsMutating/BaseExample.svelte index 73f9669890..3f0fcdf45e 100644 --- a/packages/svelte-query/tests/useIsMutating/BaseExample.svelte +++ b/packages/svelte-query/tests/useIsMutating/BaseExample.svelte @@ -1,7 +1,7 @@