Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

utils.tsx

50 lines1.3 KB

1import { vi } from 'vitest'
2import { Show, createSignal, createTrackedEffect } from 'solid-js'
3import { onlineManager } from '@tanstack/query-core'
4import { render } from '@solidjs/testing-library'
5import { QueryClientProvider } from '..'
6import type { JSX } from '@solidjs/web'
7import type { ParentProps } from 'solid-js'
8import type { MockInstance } from 'vitest'
9import type { QueryClient } from '..'
10​
11export function renderWithClient(
12 client: QueryClient,
13 ui: () => JSX.Element,
14): ReturnType<typeof render> {
15 return render(() => (
16 <QueryClientProvider client={client}>{ui()}</QueryClientProvider>
17 ))
19​
20export function Blink(
21 props: {
22 duration: number
23 } & ParentProps,
24) {
25 const [shouldShow, setShouldShow] = createSignal<boolean>(true)
26​
27 createTrackedEffect(() => {
28 setShouldShow(true)
29 const timeout = setActTimeout(() => setShouldShow(false), props.duration)
30 return () => clearTimeout(timeout)
31 })
32​
33 return (
34 <Show when={shouldShow()} fallback={<>off</>}>
35 <>{props.children}</>
36 </Show>
37 )
39​
40export function mockOnlineManagerIsOnline(
41 value: boolean,
42): MockInstance<() => boolean> {
43 return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
45​
46export function setActTimeout(fn: () => void, ms?: number) {
47 return setTimeout(() => {
48 fn()
49 }, ms)