-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathdevtools.test.tsx
More file actions
60 lines (48 loc) · 1.83 KB
/
devtools.test.tsx
File metadata and controls
60 lines (48 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { afterEach, describe, expect, it, vi } from 'vitest'
import { render } from '@solidjs/testing-library'
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
import { TanstackQueryDevtools } from '@tanstack/query-devtools'
import SolidQueryDevtools from '../devtools'
describe('SolidQueryDevtools', () => {
afterEach(() => {
vi.restoreAllMocks()
})
it('should throw an error if no query client has been set', () => {
expect(() => render(() => <SolidQueryDevtools />)).toThrow(
'No QueryClient set, use QueryClientProvider to set one',
)
})
it('should not throw an error if query client is provided via context', () => {
const queryClient = new QueryClient()
expect(() =>
render(() => (
<QueryClientProvider client={queryClient}>
<SolidQueryDevtools />
</QueryClientProvider>
)),
).not.toThrow()
})
it('should not throw an error if query client is provided via props', () => {
const queryClient = new QueryClient()
expect(() =>
render(() => <SolidQueryDevtools client={queryClient} />),
).not.toThrow()
})
it('should forward "buttonPosition" to the devtools instance', () => {
const setButtonPosition = vi.spyOn(
TanstackQueryDevtools.prototype,
'setButtonPosition',
)
const queryClient = new QueryClient()
render(() => (
<SolidQueryDevtools client={queryClient} buttonPosition="top-left" />
))
expect(setButtonPosition).toHaveBeenCalledWith('top-left')
})
it('should forward "position" to the devtools instance', () => {
const setPosition = vi.spyOn(TanstackQueryDevtools.prototype, 'setPosition')
const queryClient = new QueryClient()
render(() => <SolidQueryDevtools client={queryClient} position="left" />)
expect(setPosition).toHaveBeenCalledWith('left')
})
})