diff --git a/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx b/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx new file mode 100644 index 00000000000..01c8969f3ae --- /dev/null +++ b/packages/query-devtools/src/__tests__/TanstackQueryDevtools.test.tsx @@ -0,0 +1,59 @@ +import { beforeEach, describe, expect, it } from 'vitest' +import { QueryClient, onlineManager } from '@tanstack/query-core' +import { TanstackQueryDevtools } from '..' + +describe('TanstackQueryDevtools', () => { + let devtools: TanstackQueryDevtools + + beforeEach(() => { + devtools = new TanstackQueryDevtools({ + client: new QueryClient(), + queryFlavor: 'TanStack Query', + version: '5', + onlineManager, + }) + }) + + describe('mount', () => { + it('should mount devtools to the provided element', () => { + const el = document.createElement('div') + + expect(() => devtools.mount(el)).not.toThrow() + + devtools.unmount() + }) + + it('should throw if mount is called twice without unmount', () => { + const el = document.createElement('div') + devtools.mount(el) + + expect(() => devtools.mount(el)).toThrow('Devtools is already mounted') + + devtools.unmount() + }) + }) + + describe('unmount', () => { + it('should unmount devtools and allow remounting', () => { + const el = document.createElement('div') + devtools.mount(el) + + expect(() => devtools.unmount()).not.toThrow() + expect(() => devtools.mount(el)).not.toThrow() + + devtools.unmount() + }) + + it('should throw if unmount is called before mount', () => { + expect(() => devtools.unmount()).toThrow('Devtools is not mounted') + }) + + it('should throw if unmount is called twice', () => { + const el = document.createElement('div') + devtools.mount(el) + devtools.unmount() + + expect(() => devtools.unmount()).toThrow('Devtools is not mounted') + }) + }) +}) diff --git a/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx b/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx new file mode 100644 index 00000000000..1993ef67798 --- /dev/null +++ b/packages/query-devtools/src/__tests__/TanstackQueryDevtoolsPanel.test.tsx @@ -0,0 +1,59 @@ +import { beforeEach, describe, expect, it } from 'vitest' +import { QueryClient, onlineManager } from '@tanstack/query-core' +import { TanstackQueryDevtoolsPanel } from '..' + +describe('TanstackQueryDevtoolsPanel', () => { + let devtools: TanstackQueryDevtoolsPanel + + beforeEach(() => { + devtools = new TanstackQueryDevtoolsPanel({ + client: new QueryClient(), + queryFlavor: 'TanStack Query', + version: '5', + onlineManager, + }) + }) + + describe('mount', () => { + it('should mount devtools to the provided element', () => { + const el = document.createElement('div') + + expect(() => devtools.mount(el)).not.toThrow() + + devtools.unmount() + }) + + it('should throw if mount is called twice without unmount', () => { + const el = document.createElement('div') + devtools.mount(el) + + expect(() => devtools.mount(el)).toThrow('Devtools is already mounted') + + devtools.unmount() + }) + }) + + describe('unmount', () => { + it('should unmount devtools and allow remounting', () => { + const el = document.createElement('div') + devtools.mount(el) + + expect(() => devtools.unmount()).not.toThrow() + expect(() => devtools.mount(el)).not.toThrow() + + devtools.unmount() + }) + + it('should throw if unmount is called before mount', () => { + expect(() => devtools.unmount()).toThrow('Devtools is not mounted') + }) + + it('should throw if unmount is called twice', () => { + const el = document.createElement('div') + devtools.mount(el) + devtools.unmount() + + expect(() => devtools.unmount()).toThrow('Devtools is not mounted') + }) + }) +}) diff --git a/packages/query-devtools/src/__tests__/devtools.test.tsx b/packages/query-devtools/src/__tests__/devtools.test.tsx deleted file mode 100644 index 0e44d74db67..00000000000 --- a/packages/query-devtools/src/__tests__/devtools.test.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { describe, expect, it } from 'vitest' - -describe('ReactQueryDevtools', () => { - it('should be able to open and close devtools', () => { - expect(1).toBe(1) - }) -})