Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions packages/solid-query-devtools/src/__tests__/devtools.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createSignal } from 'solid-js'
import { render } from '@solidjs/testing-library'
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
Expand All @@ -12,6 +12,12 @@ import type {
} from '@tanstack/query-devtools'

describe('SolidQueryDevtools', () => {
let queryClient: QueryClient

beforeEach(() => {
queryClient = new QueryClient()
})

afterEach(() => {
vi.restoreAllMocks()
})
Expand All @@ -23,8 +29,6 @@ describe('SolidQueryDevtools', () => {
})

it('should not throw an error if query client is provided via context', () => {
const queryClient = new QueryClient()

expect(() =>
render(() => (
<QueryClientProvider client={queryClient}>
Expand All @@ -35,8 +39,6 @@ describe('SolidQueryDevtools', () => {
})

it('should not throw an error if query client is provided via props', () => {
const queryClient = new QueryClient()

expect(() =>
render(() => <SolidQueryDevtools client={queryClient} />),
).not.toThrow()
Expand All @@ -47,8 +49,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setButtonPosition',
)
const queryClient = new QueryClient()

render(() => (
<SolidQueryDevtools client={queryClient} buttonPosition="top-left" />
))
Expand All @@ -58,8 +58,6 @@ describe('SolidQueryDevtools', () => {

it('should forward "position" to the devtools instance', () => {
const setPosition = vi.spyOn(TanstackQueryDevtools.prototype, 'setPosition')
const queryClient = new QueryClient()

render(() => <SolidQueryDevtools client={queryClient} position="left" />)

expect(setPosition).toHaveBeenCalledWith('left')
Expand All @@ -70,8 +68,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setInitialIsOpen',
)
const queryClient = new QueryClient()

render(() => (
<SolidQueryDevtools client={queryClient} initialIsOpen={true} />
))
Expand All @@ -84,8 +80,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setInitialIsOpen',
)
const queryClient = new QueryClient()

render(() => <SolidQueryDevtools client={queryClient} />)

expect(setInitialIsOpen).toHaveBeenCalledWith(false)
Expand All @@ -96,7 +90,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
const errorTypes = [
{ name: 'Network', initializer: () => new Error('Network') },
]
Expand All @@ -113,35 +106,27 @@ describe('SolidQueryDevtools', () => {
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)
Expand All @@ -152,7 +137,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setButtonPosition',
)
const queryClient = new QueryClient()
const [buttonPosition, setButtonPositionSignal] =
createSignal<DevtoolsButtonPosition>('bottom-right')

Expand All @@ -171,7 +155,6 @@ describe('SolidQueryDevtools', () => {

it('should forward a "position" change to the devtools instance after mount', () => {
const setPosition = vi.spyOn(TanstackQueryDevtools.prototype, 'setPosition')
const queryClient = new QueryClient()
const [position, setPositionSignal] =
createSignal<DevtoolsPosition>('bottom')

Expand All @@ -190,7 +173,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setInitialIsOpen',
)
const queryClient = new QueryClient()
const [initialIsOpen, setInitialIsOpenSignal] = createSignal(false)

render(() => (
Expand All @@ -211,7 +193,6 @@ describe('SolidQueryDevtools', () => {
TanstackQueryDevtools.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
const [errorTypes, setErrorTypesSignal] = createSignal<
Array<DevtoolsErrorType>
>([])
Expand All @@ -231,7 +212,6 @@ describe('SolidQueryDevtools', () => {

it('should forward a "theme" change to the devtools instance after mount', () => {
const setTheme = vi.spyOn(TanstackQueryDevtools.prototype, 'setTheme')
const queryClient = new QueryClient()
const [theme, setThemeSignal] = createSignal<Theme>('light')

render(() => <SolidQueryDevtools client={queryClient} theme={theme()} />)
Expand All @@ -244,8 +224,6 @@ describe('SolidQueryDevtools', () => {

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} />
))
Expand Down
30 changes: 7 additions & 23 deletions packages/solid-query-devtools/src/__tests__/devtoolsPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { render } from '@solidjs/testing-library'
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
import { TanstackQueryDevtoolsPanel } from '@tanstack/query-devtools'
import SolidQueryDevtoolsPanel from '../devtoolsPanel'

describe('SolidQueryDevtoolsPanel', () => {
let queryClient: QueryClient

beforeEach(() => {
queryClient = new QueryClient()
})

afterEach(() => {
vi.restoreAllMocks()
})
Expand All @@ -16,8 +22,6 @@ describe('SolidQueryDevtoolsPanel', () => {
})

it('should not throw an error if query client is provided via context', () => {
const queryClient = new QueryClient()

expect(() =>
render(() => (
<QueryClientProvider client={queryClient}>
Expand All @@ -28,8 +32,6 @@ describe('SolidQueryDevtoolsPanel', () => {
})

it('should not throw an error if query client is provided via props', () => {
const queryClient = new QueryClient()

expect(() =>
render(() => <SolidQueryDevtoolsPanel client={queryClient} />),
).not.toThrow()
Expand All @@ -40,7 +42,6 @@ describe('SolidQueryDevtoolsPanel', () => {
TanstackQueryDevtoolsPanel.prototype,
'setOnClose',
)
const queryClient = new QueryClient()
const onClose = vi.fn()

render(() => (
Expand All @@ -55,8 +56,6 @@ describe('SolidQueryDevtoolsPanel', () => {
TanstackQueryDevtoolsPanel.prototype,
'setOnClose',
)
const queryClient = new QueryClient()

render(() => <SolidQueryDevtoolsPanel client={queryClient} />)

expect(setOnClose).toHaveBeenCalledWith(expect.any(Function))
Expand All @@ -67,7 +66,6 @@ describe('SolidQueryDevtoolsPanel', () => {
TanstackQueryDevtoolsPanel.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()
const errorTypes = [
{ name: 'Network', initializer: () => new Error('Network') },
]
Expand All @@ -84,26 +82,20 @@ describe('SolidQueryDevtoolsPanel', () => {
TanstackQueryDevtoolsPanel.prototype,
'setErrorTypes',
)
const queryClient = new QueryClient()

render(() => <SolidQueryDevtoolsPanel client={queryClient} />)

expect(setErrorTypes).toHaveBeenCalledWith([])
})

it('should forward "theme" to the devtools instance', () => {
const setTheme = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'setTheme')
const queryClient = new QueryClient()

render(() => <SolidQueryDevtoolsPanel client={queryClient} theme="dark" />)

expect(setTheme).toHaveBeenCalledWith('dark')
})

it('should default "theme" to "system" when the prop is omitted', () => {
const setTheme = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'setTheme')
const queryClient = new QueryClient()

render(() => <SolidQueryDevtoolsPanel client={queryClient} />)

expect(setTheme).toHaveBeenCalledWith('system')
Expand All @@ -114,16 +106,12 @@ describe('SolidQueryDevtoolsPanel', () => {
TanstackQueryDevtoolsPanel.prototype,
'setClient',
)
const queryClient = new QueryClient()

render(() => <SolidQueryDevtoolsPanel client={queryClient} />)

expect(setClient).toHaveBeenCalledWith(queryClient)
})

it('should preserve the default container height when "style" omits "height"', () => {
const queryClient = new QueryClient()

const { container } = render(() => (
<SolidQueryDevtoolsPanel
client={queryClient}
Expand All @@ -138,8 +126,6 @@ describe('SolidQueryDevtoolsPanel', () => {
})

it('should let "style" override the default container height on the rendered element', () => {
const queryClient = new QueryClient()

const { container } = render(() => (
<SolidQueryDevtoolsPanel
client={queryClient}
Expand All @@ -155,8 +141,6 @@ describe('SolidQueryDevtoolsPanel', () => {

it('should call "unmount" on the devtools instance when the component unmounts', () => {
const unmount = vi.spyOn(TanstackQueryDevtoolsPanel.prototype, 'unmount')
const queryClient = new QueryClient()

const { unmount: unmountComponent } = render(() => (
<SolidQueryDevtoolsPanel client={queryClient} />
))
Expand Down
Loading