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