-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathdevtoolsPanel.test.tsx
More file actions
135 lines (105 loc) · 4.1 KB
/
devtoolsPanel.test.tsx
File metadata and controls
135 lines (105 loc) · 4.1 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { afterEach, describe, expect, it, vi } from 'vitest'
import { render } from '@solidjs/testing-library'
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
import SolidQueryDevtoolsPanel from '../devtoolsPanel'
describe('SolidQueryDevtoolsPanel', () => {
afterEach(() => {
vi.restoreAllMocks()
})
it('should throw an error if no query client has been set', () => {
expect(() => render(() => <SolidQueryDevtoolsPanel />)).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}>
<SolidQueryDevtoolsPanel />
</QueryClientProvider>
)),
).not.toThrow()
})
it('should not throw an error if query client is provided via props', () => {
const queryClient = new QueryClient()
expect(() =>
render(() => <SolidQueryDevtoolsPanel client={queryClient} />),
).not.toThrow()
})
it('should forward "onClose" to the devtools instance', () => {
const setOnClose = vi.spyOn(
TanstackQueryDevtoolsPanel.prototype,
'setOnClose',
)
const queryClient = new QueryClient()
const onClose = vi.fn()
render(() => (
<SolidQueryDevtoolsPanel client={queryClient} onClose={onClose} />
))
expect(setOnClose).toHaveBeenCalledWith(onClose)
})
it('should default "onClose" to a no-op function when the prop is omitted', () => {
const setOnClose = vi.spyOn(
TanstackQueryDevtoolsPanel.prototype,
'setOnClose',
)
const queryClient = new QueryClient()
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
expect(setOnClose).toHaveBeenCalledWith(expect.any(Function))
})
it('should forward "errorTypes" to the devtools instance', () => {
const setErrorTypes = vi.spyOn(
TanstackQueryDevtoolsPanel.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
const errorTypes = [
{ name: 'Network', initializer: () => new Error('Network') },
]
render(() => (
<SolidQueryDevtoolsPanel client={queryClient} errorTypes={errorTypes} />
))
expect(setErrorTypes).toHaveBeenCalledWith(errorTypes)
})
it('should default "errorTypes" to an empty array when the prop is omitted', () => {
const setErrorTypes = vi.spyOn(
TanstackQueryDevtoolsPanel.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
expect(setErrorTypes).toHaveBeenCalledWith([])
})
it('should forward "theme" to the devtools instance', () => {
const setTheme = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'setTheme')
const queryClient = new QueryClient()
render(() => <SolidQueryDevtoolsPanel client={queryClient} theme="dark" />)
expect(setTheme).toHaveBeenCalledWith('dark')
})
it('should default "theme" to "system" when the prop is omitted', () => {
const setTheme = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'setTheme')
const queryClient = new QueryClient()
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
expect(setTheme).toHaveBeenCalledWith('system')
})
it('should forward the resolved "QueryClient" via "setClient"', () => {
const setClient = vi.spyOn(
TanstackQueryDevtoolsPanel.prototype,
'setClient',
)
const queryClient = new QueryClient()
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
expect(setClient).toHaveBeenCalledWith(queryClient)
})
it('should call "unmount" on the devtools instance when the component unmounts', () => {
const unmount = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'unmount')
const queryClient = new QueryClient()
const { unmount: unmountComponent } = render(() => (
<SolidQueryDevtoolsPanel client={queryClient} />
))
unmountComponent()
expect(unmount).toHaveBeenCalled()
})
})