-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
51 lines (45 loc) · 1 KB
/
vitest.setup.ts
File metadata and controls
51 lines (45 loc) · 1 KB
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
import '@testing-library/jest-dom/vitest'
import { beforeEach, vi } from 'vitest'
globalThis.jest = vi
vi.mock('next/router', () => ({
useRouter() {
return {
route: '/',
pathname: '',
query: {},
asPath: '',
push: vi.fn(),
replace: vi.fn(),
}
},
}))
vi.mock('next/navigation', () => ({
useRouter() {
return {
push: vi.fn(),
replace: vi.fn(),
refresh: vi.fn(),
back: vi.fn(),
}
},
usePathname() {
return ''
},
useSearchParams() {
return new URLSearchParams()
},
}))
globalThis.fetch = vi.fn() as unknown as typeof fetch
globalThis.mockFetch = (data: unknown) => {
;(
globalThis.fetch as unknown as ReturnType<typeof vi.fn>
).mockImplementationOnce(() =>
Promise.resolve({
json: () => Promise.resolve(data),
})
)
}
beforeEach(() => {
// Note: Not clearing mocks globally to preserve test-specific mock setup
// Individual test files can call vi.clearAllMocks() or vi.resetAllMocks() as needed
})