-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
62 lines (55 loc) 路 1.69 KB
/
Copy pathjest.setup.js
File metadata and controls
62 lines (55 loc) 路 1.69 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
import '@testing-library/jest-dom'
import { TextDecoder, TextEncoder } from 'util'
global.TextDecoder = TextDecoder
global.TextEncoder = TextEncoder
// Domain/component tests assert events without running Next background tasks.
// telemetry.test.ts unmocks this boundary to verify actual deferred delivery.
jest.mock('@/server/telemetry', () => ({
captureServerEvent: (client, event) => client.capture(event),
}))
// Mock next/navigation
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
refresh: jest.fn(),
}),
useSearchParams: () => ({
get: jest.fn(),
}),
usePathname: () => '/',
}))
// Clerk's <Show when="signed-in|signed-out"> renders exactly one branch at
// runtime. Tests select which via global.__setClerkAuthState. Defaults to
// signed-out, the state the marketing pages are written for.
let mockClerkAuthState = 'signed-out'
global.__setClerkAuthState = (state) => {
mockClerkAuthState = state
}
// Mock clerk/nextjs
jest.mock('@clerk/nextjs', () => ({
auth: () => ({
userId: 'test-user-id',
}),
currentUser: () => ({
id: 'test-user-id',
email: 'test@example.com',
}),
Show: ({ when, children }) => (when === mockClerkAuthState ? children : null),
SignInButton: ({ children }) => children,
SignUpButton: ({ children }) => children,
UserButton: () => null,
OrganizationSwitcher: () => null,
}))
// Mock PostHog
jest.mock('@/app/posthog', () => ({
__esModule: true,
default: () => ({
capture: jest.fn(),
}),
}))
// Mock posthog-js/react (client-side analytics)
jest.mock('posthog-js/react', () => ({
usePostHog: () => ({ capture: jest.fn() }),
PostHogProvider: ({ children }) => children,
}))