-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetupTests.js
More file actions
59 lines (53 loc) · 1.34 KB
/
setupTests.js
File metadata and controls
59 lines (53 loc) · 1.34 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
import '@testing-library/jest-dom'
import { jest } from '@jest/globals'
import dotenvFlow from 'dotenv-flow'
dotenvFlow.config({ silent: true })
// Mock Sentry module so tests can load API routes
jest.mock('@sentry/nextjs', () => {
const mockScope = {
setTag: jest.fn(),
setContext: jest.fn(),
setFingerprint: jest.fn(),
addEventProcessor: jest.fn(),
}
return {
__esModule: true,
init: jest.fn(() => 'Sentry.init'),
captureException: jest.fn(() => 'Sentry.captureException'),
configureScope: jest.fn(() => 'Sentry.configureScope'),
setUser: jest.fn(() => 'Sentry.setUser'),
setTag: jest.fn(() => 'Sentry.setTag'),
withScope: jest.fn((callback) => {
callback(mockScope)
return 'Sentry.withScope'
}),
getCurrentScope: jest.fn(() => mockScope),
}
})
jest.mock('next/router', () => ({
useRouter: jest.fn(),
}))
import { useRouter } from 'next/router'
useRouter.mockReturnValue({
route: '/',
pathname: '/',
query: {},
asPath: '/',
basePath: '',
push: jest.fn(),
replace: jest.fn(),
reload: jest.fn(),
back: jest.fn(),
forward: jest.fn(),
prefetch: jest.fn().mockResolvedValue(undefined),
beforePopState: jest.fn(),
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
},
isFallback: false,
isLocaleDomain: false,
isReady: true,
isPreview: false,
})