Open History to see the last commit
1import type { Mock } from 'vitest'
2β
3export function sleep(ms: number) {
4 return new Promise<void>((resolve) => setTimeout(resolve, ms))
5}
6β
7export function createTimer() {
8 let time = Date.now()
9β
10 return {
11 start: () => {
12 time = Date.now()
13 },
14 getTime: () => {
15 return Date.now() - time
16 },
17 }
18}
19β
20export const getIntersectionObserverMock = ({
21 observe,
22 disconnect,
23}: {
24 observe: Mock
25 disconnect: Mock
26}) => {
27 return class IO implements IntersectionObserver {
28 root: Document | Element | null
29 rootMargin: string
30 thresholds: Array<number>
31 constructor(
32 _cb: IntersectionObserverCallback,
33 options?: IntersectionObserverInit,
34 ) {
35 this.root = options?.root ?? null
36 this.rootMargin = options?.rootMargin ?? '0px'
37 this.thresholds = options?.threshold ?? ([0] as any)
38 }
39β
40 takeRecords(): Array<IntersectionObserverEntry> {
41 return []
42 }
43 unobserve(): void {}
44 observe(): void {
45 observe()
46 }
47 disconnect(): void {
48 disconnect()
49 }
50 }
51}
52β
53export function getSearchParamsFromURI(uri: string) {
54 const [, paramString] = uri.split('?')
55 return new URLSearchParams(paramString)
56}