Skip to content

Commit

Permalink
fix a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhihengGet committed Jul 17, 2024
1 parent 1274401 commit 12b0ed8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import { createQuery } from '@tanstack/svelte-query'
import { sleep } from '../utils'
export let key: Array<string>
export let states: Array<string>
let { key, states = $bindable() }: { key: string[]; states: string[] } =
$props()
const state = createQuery({
queryKey: key,
queryFn: async () => {
states = [...states, 'fetching']
states.push('fetching')
await sleep(10)
states = [...states, 'fetched']
states.push('fetched')
return 'fetched'
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@
import type { OmitKeyof, QueryClient } from '@tanstack/svelte-query'
import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
export let queryClient: QueryClient
export let persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
export let key: Array<string>
export let onSuccess: () => Promise<void>
export let states: Array<string>
interface Props {
queryClient: QueryClient
persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
key: Array<string>
onSuccess: () => Promise<void>
states: Array<string>
}
let {
queryClient,
persistOptions,
key,
onSuccess,
states = $bindable(),
}: Props = $props()
</script>

<PersistQueryClientProvider client={queryClient} {persistOptions} {onSuccess}>
<AwaitOnSuccess {key} {states} />
<AwaitOnSuccess {key} bind:states />
</PersistQueryClientProvider>
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe('PersistQueryClientProvider', () => {
await waitFor(() => rendered.getByText('fetched'))
})

test('should await onSuccess after successful restoring', async () => {
test.only('should await onSuccess after successful restoring', async () => {
const key = queryKey()

const queryClient = createQueryClient()
Expand All @@ -326,9 +326,8 @@ describe('PersistQueryClientProvider', () => {
key,
states,
onSuccess: async () => {
states = [...states, 'onSuccess']
await sleep(20)
states = [...states, 'onSuccess done']
states.push('onSuccess')
states.push('onSuccess done')
},
},
})
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-query-persist-client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
name: packageJson.name,
dir: './tests',
watch: false,
include: ['**/*.test.svelte.ts'],
environment: 'jsdom',
setupFiles: ['./tests/test-setup.ts'],
coverage: { enabled: true, provider: 'istanbul', include: ['src/**/*'] },
Expand Down

0 comments on commit 12b0ed8

Please sign in to comment.