Skip to content

Commit 6fa179d

Browse files
test(solid-query-devtools/devtoolsPanel): add wiring and default-value cases for 'onClose', 'errorTypes', 'theme', 'setClient', and 'unmount' (#10827)
* test(solid-query-devtools/devtoolsPanel): add wiring and default-value cases for 'onClose', 'errorTypes', 'theme', 'setClient', and 'unmount' * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent dcdd552 commit 6fa179d

1 file changed

Lines changed: 104 additions & 1 deletion

File tree

packages/solid-query-devtools/src/__tests__/devtoolsPanel.test.tsx

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { afterEach, describe, expect, it, vi } from 'vitest'
22
import { render } from '@solidjs/testing-library'
33
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
4+
import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
45
import SolidQueryDevtoolsPanel from '../devtoolsPanel'
56

67
describe('SolidQueryDevtoolsPanel', () => {
8+
afterEach(() => {
9+
vi.restoreAllMocks()
10+
})
11+
712
it('should throw an error if no query client has been set', () => {
813
expect(() => render(() => <SolidQueryDevtoolsPanel />)).toThrow(
914
'No QueryClient set, use QueryClientProvider to set one',
@@ -29,4 +34,102 @@ describe('SolidQueryDevtoolsPanel', () => {
2934
render(() => <SolidQueryDevtoolsPanel client={queryClient} />),
3035
).not.toThrow()
3136
})
37+
38+
it('should forward "onClose" to the devtools instance', () => {
39+
const setOnClose = vi.spyOn(
40+
TanstackQueryDevtoolsPanel.prototype,
41+
'setOnClose',
42+
)
43+
const queryClient = new QueryClient()
44+
const onClose = vi.fn()
45+
46+
render(() => (
47+
<SolidQueryDevtoolsPanel client={queryClient} onClose={onClose} />
48+
))
49+
50+
expect(setOnClose).toHaveBeenCalledWith(onClose)
51+
})
52+
53+
it('should default "onClose" to a no-op function when the prop is omitted', () => {
54+
const setOnClose = vi.spyOn(
55+
TanstackQueryDevtoolsPanel.prototype,
56+
'setOnClose',
57+
)
58+
const queryClient = new QueryClient()
59+
60+
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
61+
62+
expect(setOnClose).toHaveBeenCalledWith(expect.any(Function))
63+
})
64+
65+
it('should forward "errorTypes" to the devtools instance', () => {
66+
const setErrorTypes = vi.spyOn(
67+
TanstackQueryDevtoolsPanel.prototype,
68+
'setErrorTypes',
69+
)
70+
const queryClient = new QueryClient()
71+
const errorTypes = [
72+
{ name: 'Network', initializer: () => new Error('Network') },
73+
]
74+
75+
render(() => (
76+
<SolidQueryDevtoolsPanel client={queryClient} errorTypes={errorTypes} />
77+
))
78+
79+
expect(setErrorTypes).toHaveBeenCalledWith(errorTypes)
80+
})
81+
82+
it('should default "errorTypes" to an empty array when the prop is omitted', () => {
83+
const setErrorTypes = vi.spyOn(
84+
TanstackQueryDevtoolsPanel.prototype,
85+
'setErrorTypes',
86+
)
87+
const queryClient = new QueryClient()
88+
89+
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
90+
91+
expect(setErrorTypes).toHaveBeenCalledWith([])
92+
})
93+
94+
it('should forward "theme" to the devtools instance', () => {
95+
const setTheme = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'setTheme')
96+
const queryClient = new QueryClient()
97+
98+
render(() => <SolidQueryDevtoolsPanel client={queryClient} theme="dark" />)
99+
100+
expect(setTheme).toHaveBeenCalledWith('dark')
101+
})
102+
103+
it('should default "theme" to "system" when the prop is omitted', () => {
104+
const setTheme = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'setTheme')
105+
const queryClient = new QueryClient()
106+
107+
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
108+
109+
expect(setTheme).toHaveBeenCalledWith('system')
110+
})
111+
112+
it('should forward the resolved "QueryClient" via "setClient"', () => {
113+
const setClient = vi.spyOn(
114+
TanstackQueryDevtoolsPanel.prototype,
115+
'setClient',
116+
)
117+
const queryClient = new QueryClient()
118+
119+
render(() => <SolidQueryDevtoolsPanel client={queryClient} />)
120+
121+
expect(setClient).toHaveBeenCalledWith(queryClient)
122+
})
123+
124+
it('should call "unmount" on the devtools instance when the component unmounts', () => {
125+
const unmount = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'unmount')
126+
const queryClient = new QueryClient()
127+
128+
const { unmount: unmountComponent } = render(() => (
129+
<SolidQueryDevtoolsPanel client={queryClient} />
130+
))
131+
unmountComponent()
132+
133+
expect(unmount).toHaveBeenCalled()
134+
})
32135
})

0 commit comments

Comments
 (0)