-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathdevtools.test.tsx
More file actions
131 lines (101 loc) · 3.97 KB
/
devtools.test.tsx
File metadata and controls
131 lines (101 loc) · 3.97 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
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 "initialIsOpen" to the devtools instance', () => {
const setInitialIsOpen = vi.spyOn(
TanstackQueryDevtools.prototype,
'setInitialIsOpen',
)
const queryClient = new QueryClient()
render(() => (
<SolidQueryDevtools client={queryClient} initialIsOpen={true} />
))
expect(setInitialIsOpen).toHaveBeenCalledWith(true)
})
it('should default "initialIsOpen" to "false" when the prop is omitted', () => {
const setInitialIsOpen = vi.spyOn(
TanstackQueryDevtools.prototype,
'setInitialIsOpen',
)
const queryClient = new QueryClient()
render(() => <SolidQueryDevtools client={queryClient} />)
expect(setInitialIsOpen).toHaveBeenCalledWith(false)
})
it('should forward "errorTypes" to the devtools instance', () => {
const setErrorTypes = vi.spyOn(
TanstackQueryDevtools.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
const errorTypes = [
{ name: 'Network', initializer: () => new Error('Network') },
]
render(() => (
<SolidQueryDevtools 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(
TanstackQueryDevtools.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
render(() => <SolidQueryDevtools client={queryClient} />)
expect(setErrorTypes).toHaveBeenCalledWith([])
})
it('should forward "theme" to the devtools instance', () => {
const setTheme = vi.spyOn(TanstackQueryDevtools.prototype, 'setTheme')
const queryClient = new QueryClient()
render(() => <SolidQueryDevtools client={queryClient} theme="dark" />)
expect(setTheme).toHaveBeenCalledWith('dark')
})
it('should default "theme" to "system" when the prop is omitted', () => {
const setTheme = vi.spyOn(TanstackQueryDevtools.prototype, 'setTheme')
const queryClient = new QueryClient()
render(() => <SolidQueryDevtools client={queryClient} />)
expect(setTheme).toHaveBeenCalledWith('system')
})
it('should forward the resolved "QueryClient" via "setClient"', () => {
const setClient = vi.spyOn(TanstackQueryDevtools.prototype, 'setClient')
const queryClient = new QueryClient()
render(() => <SolidQueryDevtools client={queryClient} />)
expect(setClient).toHaveBeenCalledWith(queryClient)
})
it('should call "unmount" on the devtools instance when the component unmounts', () => {
const unmount = vi.spyOn(TanstackQueryDevtools.prototype, 'unmount')
const queryClient = new QueryClient()
const { unmount: unmountComponent } = render(() => (
<SolidQueryDevtools client={queryClient} />
))
unmountComponent()
expect(unmount).toHaveBeenCalled()
})
})