-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
55 lines (49 loc) · 1.31 KB
/
jest.setup.js
File metadata and controls
55 lines (49 loc) · 1.31 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
import '@testing-library/jest-dom'
// Mock Next.js router
jest.mock('next/router', () => ({
useRouter: () => ({
route: '/',
pathname: '/',
query: {},
asPath: '/',
push: jest.fn(),
replace: jest.fn(),
reload: jest.fn(),
back: jest.fn(),
prefetch: jest.fn().mockResolvedValue(undefined),
beforePopState: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
},
isFallback: false,
isReady: true,
}),
}))
// Mock window.crypto for better-auth
Object.defineProperty(window, 'crypto', {
value: {
randomUUID: () => 'mock-uuid-' + Math.random().toString(36).substr(2, 9),
getRandomValues: (arr) => {
for (let i = 0; i < arr.length; i++) {
arr[i] = Math.floor(Math.random() * 256)
}
return arr
},
},
})
// Mock fetch for API calls
global.fetch = jest.fn()
// Suppress console warnings in tests
const originalConsoleWarn = console.warn
const originalConsoleError = console.error
beforeEach(() => {
console.warn = jest.fn()
console.error = jest.fn()
})
afterEach(() => {
console.warn = originalConsoleWarn
console.error = originalConsoleError
jest.clearAllMocks()
})