Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

Devtools.svelte.test.ts

39 lines1.3 KB

1import { describe, expect, it } from 'vitest'
2import { render } from '@testing-library/svelte'
3import { QueryClient } from '@tanstack/svelte-query'
4import SvelteQueryDevtools from '../src/Devtools.svelte'
5import Wrapper from './Wrapper.svelte'
6​
7describe('SvelteQueryDevtools', () => {
8 it('should render the parent container without throwing in non-development environments', () => {
9 const queryClient = new QueryClient()
10​
11 const { container } = render(SvelteQueryDevtools, {
12 props: { client: queryClient },
13 })
14​
15 expect(
16 container.querySelector('.tsqd-parent-container'),
17 ).toBeInTheDocument()
18 })
19​
20 it('should throw an error if no query client has been set', () => {
21 expect(() => render(SvelteQueryDevtools)).toThrow(
22 'No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?',
23 )
24 })
25​
26 it('should not throw an error if query client is provided via context', () => {
27 const queryClient = new QueryClient()
28​
29 expect(() => render(Wrapper, { props: { queryClient } })).not.toThrow()
30 })
31​
32 it('should not throw an error if query client is provided via props', () => {
33 const queryClient = new QueryClient()
34​
35 expect(() =>
36 render(SvelteQueryDevtools, { props: { client: queryClient } }),
37 ).not.toThrow()
38 })
39})