-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
40 lines (32 loc) · 1.01 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
import '@testing-library/jest-dom'
// ------------------------------------------------------------------------------
class MockIntersectionObserver {
callback: IntersectionObserverCallback
options: IntersectionObserverInit
observe: jest.Mock
unobserve: jest.Mock
disconnect: jest.Mock
constructor(
callback: IntersectionObserverCallback,
options?: IntersectionObserverInit
) {
this.callback = callback
this.options = options || {}
this.observe = jest.fn()
this.unobserve = jest.fn()
this.disconnect = jest.fn()
}
trigger(entries: IntersectionObserverEntry[]) {
this.callback(entries, this as unknown as IntersectionObserver)
}
}
global.IntersectionObserver = MockIntersectionObserver as never
// ------------------------------------------------------------------------------
const testCache = <T extends Function>(func: T) => func
jest.mock('react', () => {
const originalModule = jest.requireActual('react')
return {
...originalModule,
cache: testCache
}
})