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 type { ParentProps } from 'solid-js'
5import type { MockInstance } from 'vitest'
6β
7export function Blink(
8 props: {
9 duration: number
10 } & ParentProps,
11) {
12 const [shouldShow, setShouldShow] = createSignal<boolean>(true)
13β
14 createEffect(() => {
15 setShouldShow(true)
16 const timeout = setActTimeout(() => setShouldShow(false), props.duration)
17 onCleanup(() => clearTimeout(timeout))
18 })
19β
20 return (
21 <Show when={shouldShow()} fallback={<>off</>}>
22 <>{props.children}</>
23 </Show>
24 )
25}
26β
27export function mockOnlineManagerIsOnline(
28 value: boolean,
29): MockInstance<() => boolean> {
30 return vi.spyOn(onlineManager, 'isOnline').mockReturnValue(value)
31}
32β
33export function setActTimeout(fn: () => void, ms?: number) {
34 return setTimeout(() => {
35 fn()
36 }, ms)
37}