|
| 1 | +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { QueryClient, onlineManager } from '@tanstack/query-core' |
| 3 | +import { render } from '@solidjs/testing-library' |
| 4 | +import DevtoolsComponent from '../DevtoolsComponent' |
| 5 | + |
| 6 | +vi.mock('solid-transition-group', () => ({ |
| 7 | + TransitionGroup: (props: { children: unknown }) => props.children, |
| 8 | +})) |
| 9 | + |
| 10 | +describe('DevtoolsComponent', () => { |
| 11 | + const storage: { [key: string]: string } = {} |
| 12 | + let queryClient: QueryClient |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + Object.defineProperty(window, 'localStorage', { |
| 16 | + value: { |
| 17 | + getItem: (key: string) => storage[key] || null, |
| 18 | + setItem: (key: string, value: string) => { |
| 19 | + storage[key] = value |
| 20 | + }, |
| 21 | + removeItem: (key: string) => { |
| 22 | + delete storage[key] |
| 23 | + }, |
| 24 | + clear: () => { |
| 25 | + Object.keys(storage).forEach((key) => delete storage[key]) |
| 26 | + }, |
| 27 | + }, |
| 28 | + writable: true, |
| 29 | + }) |
| 30 | + vi.stubGlobal( |
| 31 | + 'matchMedia', |
| 32 | + vi.fn().mockImplementation((query: string) => ({ |
| 33 | + matches: false, |
| 34 | + media: query, |
| 35 | + onchange: null, |
| 36 | + addEventListener: vi.fn(), |
| 37 | + removeEventListener: vi.fn(), |
| 38 | + addListener: vi.fn(), |
| 39 | + removeListener: vi.fn(), |
| 40 | + dispatchEvent: vi.fn(), |
| 41 | + })), |
| 42 | + ) |
| 43 | + vi.stubGlobal( |
| 44 | + 'ResizeObserver', |
| 45 | + class { |
| 46 | + observe = vi.fn() |
| 47 | + unobserve = vi.fn() |
| 48 | + disconnect = vi.fn() |
| 49 | + }, |
| 50 | + ) |
| 51 | + queryClient = new QueryClient() |
| 52 | + }) |
| 53 | + |
| 54 | + afterEach(() => { |
| 55 | + vi.unstubAllGlobals() |
| 56 | + Object.keys(storage).forEach((key) => delete storage[key]) |
| 57 | + queryClient.clear() |
| 58 | + }) |
| 59 | + |
| 60 | + it('should render without throwing', () => { |
| 61 | + expect(() => |
| 62 | + render(() => ( |
| 63 | + <DevtoolsComponent |
| 64 | + client={queryClient} |
| 65 | + queryFlavor="TanStack Query" |
| 66 | + version="5" |
| 67 | + onlineManager={onlineManager} |
| 68 | + /> |
| 69 | + )), |
| 70 | + ).not.toThrow() |
| 71 | + }) |
| 72 | +}) |
0 commit comments