Skip to content

Commit cb115ea

Browse files
test(react-query-devtools/ReactQueryDevtools): add tests for forwarding option changes after mount (#11019)
* test(react-query-devtools/ReactQueryDevtools): add tests for forwarding option changes after mount * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent d6798b5 commit cb115ea

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

packages/react-query-devtools/src/__tests__/ReactQueryDevtools.test.tsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,83 @@ describe('ReactQueryDevtools', () => {
182182
)
183183
})
184184

185+
it('should forward a "buttonPosition" change to the devtools instance after mount', async () => {
186+
const { ReactQueryDevtools } = await import('../ReactQueryDevtools')
187+
const queryClient = new QueryClient()
188+
189+
const { rerender } = render(
190+
<ReactQueryDevtools client={queryClient} buttonPosition="bottom-right" />,
191+
)
192+
setButtonPositionMock.mockClear()
193+
194+
rerender(
195+
<ReactQueryDevtools client={queryClient} buttonPosition="top-left" />,
196+
)
197+
198+
expect(setButtonPositionMock).toHaveBeenCalledWith('top-left')
199+
})
200+
201+
it('should forward a "position" change to the devtools instance after mount', async () => {
202+
const { ReactQueryDevtools } = await import('../ReactQueryDevtools')
203+
const queryClient = new QueryClient()
204+
205+
const { rerender } = render(
206+
<ReactQueryDevtools client={queryClient} position="bottom" />,
207+
)
208+
setPositionMock.mockClear()
209+
210+
rerender(<ReactQueryDevtools client={queryClient} position="top" />)
211+
212+
expect(setPositionMock).toHaveBeenCalledWith('top')
213+
})
214+
215+
it('should forward an "initialIsOpen" change to the devtools instance after mount', async () => {
216+
const { ReactQueryDevtools } = await import('../ReactQueryDevtools')
217+
const queryClient = new QueryClient()
218+
219+
const { rerender } = render(
220+
<ReactQueryDevtools client={queryClient} initialIsOpen={false} />,
221+
)
222+
setInitialIsOpenMock.mockClear()
223+
224+
rerender(<ReactQueryDevtools client={queryClient} initialIsOpen={true} />)
225+
226+
expect(setInitialIsOpenMock).toHaveBeenCalledWith(true)
227+
})
228+
229+
it('should forward an "errorTypes" change to the devtools instance after mount', async () => {
230+
const { ReactQueryDevtools } = await import('../ReactQueryDevtools')
231+
const queryClient = new QueryClient()
232+
233+
const { rerender } = render(
234+
<ReactQueryDevtools client={queryClient} errorTypes={[]} />,
235+
)
236+
setErrorTypesMock.mockClear()
237+
238+
const errorTypes = [
239+
{ name: 'Network', initializer: () => new Error('Network') },
240+
]
241+
rerender(
242+
<ReactQueryDevtools client={queryClient} errorTypes={errorTypes} />,
243+
)
244+
245+
expect(setErrorTypesMock).toHaveBeenCalledWith(errorTypes)
246+
})
247+
248+
it('should forward a "theme" change to the devtools instance after mount', async () => {
249+
const { ReactQueryDevtools } = await import('../ReactQueryDevtools')
250+
const queryClient = new QueryClient()
251+
252+
const { rerender } = render(
253+
<ReactQueryDevtools client={queryClient} theme="light" />,
254+
)
255+
setThemeMock.mockClear()
256+
257+
rerender(<ReactQueryDevtools client={queryClient} theme="dark" />)
258+
259+
expect(setThemeMock).toHaveBeenCalledWith('dark')
260+
})
261+
185262
it('should call "unmount" on the devtools instance when the component unmounts', async () => {
186263
const { ReactQueryDevtools } = await import('../ReactQueryDevtools')
187264
const queryClient = new QueryClient()

0 commit comments

Comments
 (0)