-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00f0d44
commit 6d6a378
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/svelte-query/tests/QueryClientProvider/ChildComponent.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import { createQuery } from '../../src/createQuery' | ||
import { sleep } from '../utils' | ||
const query = createQuery({ | ||
queryKey: ['hello'], | ||
queryFn: async () => { | ||
await sleep(10) | ||
return 'test' | ||
}, | ||
}) | ||
</script> | ||
|
||
<div>{$query.data}</div> |
14 changes: 14 additions & 0 deletions
14
packages/svelte-query/tests/QueryClientProvider/ParentComponent.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script lang="ts"> | ||
import { QueryClient } from '@tanstack/query-core' | ||
import QueryClientProvider from '../../src/QueryClientProvider.svelte' | ||
import ChildComponent from './ChildComponent.svelte' | ||
import type { QueryCache } from '@tanstack/query-core' | ||
export let queryCache: QueryCache | ||
const queryClient = new QueryClient({ queryCache }) | ||
</script> | ||
|
||
<QueryClientProvider client={queryClient}> | ||
<ChildComponent /> | ||
</QueryClientProvider> |
20 changes: 20 additions & 0 deletions
20
packages/svelte-query/tests/QueryClientProvider/QueryClientProvider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { render, waitFor } from '@testing-library/svelte' | ||
import { QueryCache } from '@tanstack/query-core' | ||
import ParentComponent from './ParentComponent.svelte' | ||
|
||
describe('QueryClientProvider', () => { | ||
test('Sets a specific cache for all queries to use', async () => { | ||
const queryCache = new QueryCache() | ||
|
||
const rendered = render(ParentComponent, { | ||
props: { | ||
queryCache: queryCache, | ||
}, | ||
}) | ||
|
||
await waitFor(() => rendered.getByText('test')) | ||
|
||
expect(queryCache.find({ queryKey: ['hello'] })).toBeDefined() | ||
}) | ||
}) |