-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitestSetup.ts
47 lines (39 loc) · 993 Bytes
/
vitestSetup.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
import Link from 'next/link'
import { vi } from 'vitest'
process.env.MOCK_PATHNAME = '/'
process.env.NEXT_PUBLIC_APP_URL = 'http://localhost.test'
vi.mock('react', async () => {
const actual = await vi.importActual('react')
return {
...actual,
useContext: () => ({ locale: { code: 'en' } }),
}
})
vi.mock('next/navigation', async () => {
const actual = await vi.importActual('next/navigation')
return {
...(actual as object),
useRouter: vi.fn(() => ({
push: vi.fn(),
})),
notFound: vi.fn(),
useSearchParams: () => {
return new URLSearchParams(process.env.MOCK_PATHNAME)
},
usePathname: () => {
return process.env.MOCK_PATHNAME
},
}
})
vi.mock('next-view-transitions', async () => {
return {
Link,
}
})
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn(),
}))
vi.stubGlobal('IntersectionObserver', IntersectionObserverMock)