import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { fireEvent, render } from '@solidjs/testing-library' import { Show, Suspense, createSignal, startTransition } from 'solid-js' import { queryKey, sleep } from '@tanstack/query-test-utils' import { QueryCache, QueryClient, QueryClientProvider, useQuery } from '..' describe("useQuery's in Suspense mode with transitions", () => { beforeEach(() => { vi.useFakeTimers() }) afterEach(() => { vi.useRealTimers() }) const queryCache = new QueryCache() const queryClient = new QueryClient({ queryCache }) it('should render the content when the transition is done', async () => { const key = queryKey() function Suspended() { const state = useQuery(() => ({ queryKey: key, queryFn: async () => { await sleep(10) return true }, })) return Message } function Page() { const [showSignal, setShowSignal] = createSignal(false) return (
) } const rendered = render(() => ( )) expect(rendered.getByText('Show')).toBeInTheDocument() fireEvent.click(rendered.getByLabelText('toggle')) await vi.advanceTimersByTimeAsync(10) expect(rendered.getByText('Message')).toBeInTheDocument() // verify that the button also updated. See https://github.com/solidjs/solid/issues/1249 expect(rendered.getByText('Hide')).toBeInTheDocument() }) })