-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathjest.setup.js
More file actions
66 lines (56 loc) · 1.13 KB
/
jest.setup.js
File metadata and controls
66 lines (56 loc) · 1.13 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Import Jest DOM extensions
import '@testing-library/jest-dom'
// Add jest to global scope for ESLint
/* global jest, beforeEach */
// Mock Next.js router
jest.mock('next/router', () => ({
__esModule: true,
default: {
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
reload: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
},
beforePopState: jest.fn(() => null),
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
}),
},
}))
// Mock localStorage
class LocalStorageMock {
constructor() {
this.store = {}
}
clear() {
this.store = {}
}
getItem(key) {
return this.store[key] || null
}
setItem(key, value) {
this.store[key] = String(value)
}
removeItem(key) {
delete this.store[key]
}
}
global.localStorage = new LocalStorageMock()
// Mock fetch API
global.fetch = jest.fn()
global.AbortSignal = {
timeout: jest.fn(() => ({})),
}
// Reset mocks between tests
beforeEach(() => {
jest.clearAllMocks()
localStorage.clear()
})