Open History to see the last commit
1import type { QueryClientConfig } from '@tanstack/query-core'
2import { QueryClient } from '@tanstack/query-core'
3import type { ParentProps } from 'solid-js'
4import { createEffect, createSignal, onCleanup, Show } from 'solid-js'
5β
6let queryKeyCount = 0
7export function queryKey(): Array<string> {
8 queryKeyCount++
9 return [`query_${queryKeyCount}`]
10}
11β
12export const Blink = (
13 props: {
14 duration: number
15 } & ParentProps,
16) => {
17 const [shouldShow, setShouldShow] = createSignal<boolean>(true)
18β
19 createEffect(() => {
20 setShouldShow(true)
21 const timeout = setActTimeout(() => setShouldShow(false), props.duration)
22 onCleanup(() => clearTimeout(timeout))
23 })
24β
25 return (
26 <Show when={shouldShow()} fallback={<>off</>}>
27 <>{props.children}</>
28 </Show>
29 )
30}
31β
32export function createQueryClient(config?: QueryClientConfig): QueryClient {
33 return new QueryClient(config)
34}
35β
36export function mockVisibilityState(value: DocumentVisibilityState) {
37 return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
38}
39β
40export function mockNavigatorOnLine(value: boolean) {
41 return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
42}
43β
44export function sleep(timeout: number): Promise<void> {
45 return new Promise((resolve, _reject) => {
46 setTimeout(resolve, timeout)
47 })
48}
49β
50export function setActTimeout(fn: () => void, ms?: number) {
51 return setTimeout(() => {
52 fn()
53 }, ms)
54}
55β
56/**
57 * Assert the parameter is of a specific type.
58 */
59export function expectType<T>(_: T): void {
60 return undefined
61}
62β
63/**
64 * Assert the parameter is not typed as `any`
65 */
66export function expectTypeNotAny<T>(_: 0 extends 1 & T ? never : T): void {
67 return undefined
68}