Skip to content

Commit

Permalink
Fix svelte-query-persist-client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlancollins committed Jul 17, 2024
1 parent ee98bef commit c1b7778
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import type { StatusResult } from '../utils.svelte'
let {
key,
states,
}: {
key: Array<string>
states: { value: Array<StatusResult<string>> }
fetched: boolean
} = $props()
Expand All @@ -29,5 +27,5 @@
})
</script>

<div>data: {$query.data ?? 'null'}</div>
<div>fetchStatus: {$query.fetchStatus}</div>
<div>data: {query.data ?? 'undefined'}</div>
<div>fetchStatus: {query.fetchStatus}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
states: { value: Array<StatusResult<string>> }
fetched: boolean
}
let { queryClient, persistOptions, key, states, fetched }: Props = $props()
let { queryClient, persistOptions, states, fetched }: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions}>
<FreshData {key} bind:states {fetched} />
<FreshData {states} {fetched} />
</PersistQueryClientProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
import { sleep } from '../utils.svelte'
import type { StatusResult } from '../utils.svelte'
let {
key,
states,
}: {
key: Array<string>
states: { value: Array<StatusResult<string>> }
} = $props()
let { states }: { states: { value: Array<StatusResult<string>> } } = $props()
const query = createQuery({
queryKey: ['test'],
Expand All @@ -30,5 +24,5 @@
})
</script>

<div>{$query.data}</div>
<div>fetchStatus: {$query.fetchStatus}</div>
<div>{query.data}</div>
<div>fetchStatus: {query.fetchStatus}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
states: { value: Array<StatusResult<string>> }
}
let { queryClient, persistOptions, key, states }: Props = $props()
let { queryClient, persistOptions, states }: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
})
</script>

<div>{$query.data}</div>
<div>fetchStatus: {$query.fetchStatus}</div>
<div>{query.data}</div>
<div>fetchStatus: {query.fetchStatus}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
onSuccess: () => void
}
let { queryClient, persistOptions, key, onSuccess }: Props = $props()
let { queryClient, persistOptions, onSuccess }: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions} {onSuccess}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import InitialData from './InitialData/Provider.svelte'
import RemoveCache from './RemoveCache/Provider.svelte'
import RestoreCache from './RestoreCache/Provider.svelte'
import UseQueries from './UseQueries/Provider.svelte'
import { createQueryClient, queryKey, ref, sleep } from './utils.svelte'
import { createQueryClient, ref, sleep } from './utils.svelte'

import type {
PersistedClient,
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('PersistQueryClientProvider', () => {
},
})

await waitFor(() => rendered.getByText('data: null'))
await waitFor(() => rendered.getByText('data: undefined'))
await waitFor(() => rendered.getByText('data: hydrated'))

expect(fetched).toBe(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
}
let { queryClient, persistOptions, key }: Props = $props()
let { queryClient, persistOptions }: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
})
</script>

<div>{$query.data}</div>
<div>fetchStatus: {$query.fetchStatus}</div>
<div>{query.data}</div>
<div>fetchStatus: {query.fetchStatus}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
states: { value: Array<StatusResult<string>> }
}
let { queryClient, persistOptions, key, states }: Props = $props()
let { queryClient, persistOptions, states }: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
import { sleep } from '../utils.svelte'
import type { StatusResult } from '../utils.svelte'
let {
key,
states,
}: {
key: Array<string>
states: { value: Array<StatusResult<string>> }
} = $props()
let { states }: { states: { value: Array<StatusResult<string>> } } = $props()
const query = createQuery({
queryKey: ['test'],
Expand All @@ -25,5 +19,5 @@
})
</script>

<div>{$query.data}</div>
<div>fetchStatus: {$query.fetchStatus}</div>
<div>{query.data}</div>
<div>fetchStatus: {query.fetchStatus}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
states: { value: Array<StatusResult<string>> }
}
let { queryClient, persistOptions, key, states }: Props = $props()
let { queryClient, persistOptions, states }: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
import { sleep } from '../utils.svelte'
import type { StatusResult } from '../utils.svelte'
let {
key,
states,
}: {
key: Array<string>
states: { value: Array<StatusResult<string>> }
} = $props()
let { states }: { states: { value: Array<StatusResult<string>> } } = $props()
const queries = createQueries({
queries: [
Expand All @@ -25,9 +19,9 @@
})
$effect(() => {
states.value = [...untrack(() => states.value), $state.snapshot(s[0])]
states.value = [...untrack(() => states.value), $state.snapshot(queries[0])]
})
</script>

<div>{$queries[0].data}</div>
<div>fetchStatus: {$queries[0].fetchStatus}</div>
<div>{queries[0].data}</div>
<div>fetchStatus: {queries[0].fetchStatus}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
queryKey: ['test'],
queryFn: async ({ pageParam }) => {
await sleep(500)
await sleep(5)
return Number(pageParam)
},
getNextPageParam: (lastPage) => lastPage + 1,
Expand Down

0 comments on commit c1b7778

Please sign in to comment.