forked from pixiv/charcoal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
52 lines (43 loc) · 1.27 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { ReactNode } from 'react'
export {}
globalThis.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}))
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
observe() {
return null
},
disconnect() {
return null
},
}))
window.matchMedia = jest.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: jest.fn(),
removeListener: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}))
jest.mock('@react-aria/utils', () => ({
...jest.requireActual('@react-aria/utils'),
useId: () => 'test-id',
}))
jest.mock('@react-aria/overlays', () => ({
...jest.requireActual('@react-aria/overlays'),
Overlay: jest.fn(({ children }: { children: ReactNode }) => children),
}))
import type { OverlayTriggerProps } from 'react-stately'
jest.mock('react-stately', () => ({
...jest.requireActual('react-stately'),
useOverlayTriggerState: (args: OverlayTriggerProps) => {
const { useOverlayTriggerState } =
jest.requireActual<typeof import('react-stately')>('react-stately')
const state = useOverlayTriggerState(args)
return { ...state, isOpen: true }
},
}))