Open History to see the last commit
1import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2import { QueryClient, onlineManager } from '@tanstack/query-core'
3import { render } from '@solidjs/testing-library'
4import DevtoolsComponent from '../DevtoolsComponent'
5β
6// `solid-transition-group` internally imports from
7// `@solid-primitives/transition-group`, whose `exports` field points at
8// `src/index.ts` (not published) under a `@solid-primitives/source` condition
9// that Vite can't fall through, so we stub it with a transparent pass-through.
10vi.mock('solid-transition-group', () => ({
11 TransitionGroup: (props: { children: unknown }) => props.children,
12}))
13β
14describe('DevtoolsComponent', () => {
15 const storage: { [key: string]: string } = {}
16 let queryClient: QueryClient
17β
18 beforeEach(() => {
19 vi.stubGlobal('localStorage', {
20 getItem: (key: string) =>
21 Object.prototype.hasOwnProperty.call(storage, key)
22 ? storage[key]
23 : null,
24 setItem: (key: string, value: string) => {
25 storage[key] = value
26 },
27 removeItem: (key: string) => {
28 delete storage[key]
29 },
30 clear: () => {
31 Object.keys(storage).forEach((key) => delete storage[key])
32 },
33 })
34 vi.stubGlobal(
35 'matchMedia',
36 vi.fn().mockImplementation((query: string) => ({
37 matches: false,
38 media: query,
39 onchange: null,
40 addEventListener: vi.fn(),
41 removeEventListener: vi.fn(),
42 addListener: vi.fn(),
43 removeListener: vi.fn(),
44 dispatchEvent: vi.fn(),
45 })),
46 )
47 vi.stubGlobal(
48 'ResizeObserver',
49 class {
50 observe = vi.fn()
51 unobserve = vi.fn()
52 disconnect = vi.fn()
53 },
54 )
55 queryClient = new QueryClient()
56 })
57β
58 afterEach(() => {
59 vi.unstubAllGlobals()
60 Object.keys(storage).forEach((key) => delete storage[key])
61 queryClient.clear()
62 })
63β
64 it('should render without throwing when only required props are provided', () => {
65 expect(() =>
66 render(() => (
67 <DevtoolsComponent
68 client={queryClient}
69 queryFlavor="TanStack Query"
70 version="5"
71 onlineManager={onlineManager}
72 />
73 )),
74 ).not.toThrow()
75 })
76β
77 it('should render without throwing when all props are provided', () => {
78 expect(() =>
79 render(() => (
80 <DevtoolsComponent
81 client={queryClient}
82 queryFlavor="TanStack Query"
83 version="5"
84 onlineManager={onlineManager}
85 buttonPosition="top-left"
86 position="left"
87 initialIsOpen={true}
88 errorTypes={[
89 { name: 'NetworkError', initializer: () => new Error('Network') },
90 ]}
91 hideDisabledQueries={true}
92 theme="dark"
93 />
94 )),
95 ).not.toThrow()
96 })
97})