This repository was archived by the owner on Feb 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
78 lines (67 loc) · 1.97 KB
/
jest.setup.js
File metadata and controls
78 lines (67 loc) · 1.97 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
67
68
69
70
71
72
73
74
75
76
77
78
import '@testing-library/jest-dom'
// Polyfill TextEncoder and TextDecoder for Node.js test environment
global.TextEncoder = global.TextEncoder || require('util').TextEncoder
global.TextDecoder = global.TextDecoder || require('util').TextDecoder
// Polyfill fetch for Node.js test environment
global.fetch = global.fetch || jest.fn()
global.Request = global.Request || class Request {}
global.Response = global.Response || class Response {
static json(data) {
return {
json: () => Promise.resolve(data),
status: 200,
ok: true
}
}
}
global.Headers = global.Headers || class Headers {}
// Polyfill for setImmediate for winston in Jest environment
if (typeof setImmediate === 'undefined') {
global.setImmediate = (fn, ...args) => global.setTimeout(fn, 0, ...args);
}
// Mock Next.js router
jest.mock('next/navigation', () => ({
useRouter() {
return {
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
forward: jest.fn(),
refresh: jest.fn(),
}
},
useSearchParams() {
return new URLSearchParams()
},
usePathname() {
return ''
},
}))
// Mock environment variables for tests
process.env.JWT_SECRET = 'test-jwt-secret-key-1234567890-abcdefghijkl'
process.env.NODE_ENV = 'test'
process.env.POSTGRES_HOST = 'localhost'
process.env.POSTGRES_PORT = '5432'
process.env.POSTGRES_DB = 'test_db'
process.env.POSTGRES_USER = 'test_user'
process.env.POSTGRES_PASSWORD = 'test_password'
// Global test setup
beforeEach(() => {
// Reset all mocks before each test
jest.clearAllMocks()
})
// Mock fetch for API tests
global.fetch = jest.fn()
// Mock console methods to reduce noise in tests
global.console = {
...console,
log: jest.fn(),
debug: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
}
// Note: Logger mocks are handled in individual test files
// Note: Database mocks are handled in individual test files
// Note: Config mocks are handled in individual test files