-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
66 lines (55 loc) · 1.31 KB
/
jest.setup.js
File metadata and controls
66 lines (55 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
56
57
58
59
60
61
62
63
64
65
66
// Learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom'
import { TextDecoder, TextEncoder } from 'util'
// Mock global fetch
global.fetch = jest.fn()
// Mock Next.js router
jest.mock('next/router', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
query: {},
pathname: '/',
asPath: '/',
}),
}))
// Mock next/auth
jest.mock('next-auth/react', () => ({
useSession: jest.fn(() => ({ data: null, status: 'unauthenticated' })),
signIn: jest.fn(),
signOut: jest.fn(),
getSession: jest.fn(),
}))
// Mock IPFS client
jest.mock('ipfs-http-client', () => ({
create: jest.fn(() => ({
add: jest.fn(),
cat: jest.fn(),
pin: {
add: jest.fn(),
rm: jest.fn(),
},
})),
}))
// Setup MSW for API mocking
import { setupServer } from 'msw/node'
import { handlers } from './src/mocks/handlers'
export const server = setupServer(...handlers)
beforeAll(() => {
// Start MSW server
server.listen()
// Polyfill TextEncoder/TextDecoder for Node.js environment
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
})
afterEach(() => {
// Reset MSW handlers
server.resetHandlers()
// Clear all mocks
jest.clearAllMocks()
})
afterAll(() => {
// Clean up MSW server
server.close()
})