From 9963b2fc97dc5133a973db10e8eb741741adf76e Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 9 May 2026 17:59:10 +0900 Subject: [PATCH] test(query-devtools/TanstackQueryDevtools{,Panel}): add tests for setters (#10676) --- .../__tests__/TanstackQueryDevtools.test.tsx | 57 +++++++++++++++++ .../TanstackQueryDevtoolsPanel.test.tsx | 62 +++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx b/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx index 01c8969f3a..cef4475d83 100644 --- a/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx +++ b/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx @@ -56,4 +56,61 @@ describe('TanstackQueryDevtools', () => { expect(() => devtools.unmount()).toThrow('Devtools is not mounted') }) }) + + describe('setters', () => { + describe('before mount', () => { + it('should not throw when "setButtonPosition" is called', () => { + expect(() => devtools.setButtonPosition('top-left')).not.toThrow() + }) + + it('should not throw when "setPosition" is called', () => { + expect(() => devtools.setPosition('left')).not.toThrow() + }) + + it('should not throw when "setInitialIsOpen" is called', () => { + expect(() => devtools.setInitialIsOpen(true)).not.toThrow() + }) + + it('should not throw when "setErrorTypes" is called', () => { + expect(() => + devtools.setErrorTypes([ + { name: 'NetworkError', initializer: () => new Error('Network') }, + ]), + ).not.toThrow() + }) + + it('should not throw when "setClient" is called', () => { + expect(() => devtools.setClient(new QueryClient())).not.toThrow() + }) + + it('should not throw when "setTheme" is called', () => { + expect(() => devtools.setTheme('dark')).not.toThrow() + expect(() => devtools.setTheme('light')).not.toThrow() + expect(() => devtools.setTheme('system')).not.toThrow() + expect(() => devtools.setTheme(undefined)).not.toThrow() + }) + }) + + describe('after mount', () => { + it('should not throw when setters are called on a mounted instance', () => { + const el = document.createElement('div') + devtools.mount(el) + + try { + expect(() => devtools.setButtonPosition('top-left')).not.toThrow() + expect(() => devtools.setPosition('left')).not.toThrow() + expect(() => devtools.setInitialIsOpen(true)).not.toThrow() + expect(() => + devtools.setErrorTypes([ + { name: 'NetworkError', initializer: () => new Error('Network') }, + ]), + ).not.toThrow() + expect(() => devtools.setClient(new QueryClient())).not.toThrow() + expect(() => devtools.setTheme('dark')).not.toThrow() + } finally { + devtools.unmount() + } + }) + }) + }) }) diff --git a/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx b/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx index 1993ef6779..f7407ad5ff 100644 --- a/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx +++ b/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx @@ -56,4 +56,66 @@ describe('TanstackQueryDevtoolsPanel', () => { expect(() => devtools.unmount()).toThrow('Devtools is not mounted') }) }) + + describe('setters', () => { + describe('before mount', () => { + it('should not throw when "setButtonPosition" is called', () => { + expect(() => devtools.setButtonPosition('top-left')).not.toThrow() + }) + + it('should not throw when "setPosition" is called', () => { + expect(() => devtools.setPosition('left')).not.toThrow() + }) + + it('should not throw when "setInitialIsOpen" is called', () => { + expect(() => devtools.setInitialIsOpen(true)).not.toThrow() + }) + + it('should not throw when "setErrorTypes" is called', () => { + expect(() => + devtools.setErrorTypes([ + { name: 'NetworkError', initializer: () => new Error('Network') }, + ]), + ).not.toThrow() + }) + + it('should not throw when "setClient" is called', () => { + expect(() => devtools.setClient(new QueryClient())).not.toThrow() + }) + + it('should not throw when "setOnClose" is called', () => { + expect(() => devtools.setOnClose(() => {})).not.toThrow() + }) + + it('should not throw when "setTheme" is called', () => { + expect(() => devtools.setTheme('dark')).not.toThrow() + expect(() => devtools.setTheme('light')).not.toThrow() + expect(() => devtools.setTheme('system')).not.toThrow() + expect(() => devtools.setTheme(undefined)).not.toThrow() + }) + }) + + describe('after mount', () => { + it('should not throw when setters are called on a mounted instance', () => { + const el = document.createElement('div') + devtools.mount(el) + + try { + expect(() => devtools.setButtonPosition('top-left')).not.toThrow() + expect(() => devtools.setPosition('left')).not.toThrow() + expect(() => devtools.setInitialIsOpen(true)).not.toThrow() + expect(() => + devtools.setErrorTypes([ + { name: 'NetworkError', initializer: () => new Error('Network') }, + ]), + ).not.toThrow() + expect(() => devtools.setClient(new QueryClient())).not.toThrow() + expect(() => devtools.setOnClose(() => {})).not.toThrow() + expect(() => devtools.setTheme('dark')).not.toThrow() + } finally { + devtools.unmount() + } + }) + }) + }) })