-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTests.ts
44 lines (38 loc) · 1.13 KB
/
setupTests.ts
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
import '@testing-library/jest-dom'
import { cleanup } from '@testing-library/react'
import { toHaveNoViolations } from 'jest-axe'
expect.extend(toHaveNoViolations)
global.fetch = jest.fn(async () => new Response())
if (typeof window !== 'undefined') {
// https://github.com/jsdom/jsdom/issues/1695
window.HTMLElement.prototype.scrollIntoView = jest.fn()
window.HTMLElement.prototype.scrollTo = jest.fn()
}
jest.mock('utils/analytics/useMatomo')
jest.mock('next/navigation', () => ({
notFound: jest.fn(() => {
throw new Error('NEXT NOT_FOUND')
}),
redirect: jest.fn((destination) => {
throw new Error('NEXT_REDIRECT ' + destination)
}),
useRouter: jest.fn(),
usePathname: jest.fn(),
useSearchParams: jest.fn(),
}))
jest.mock('next/headers', () => ({ headers: jest.fn() }))
jest.mock('next-auth/react', () => ({
getSession: async () => ({
user: {
id: 'idConseiller',
estSuperviseur: false,
estSuperviseurResponsable: false,
structure: 'MILO',
},
accessToken: 'accessToken',
}),
}))
afterEach(() => {
if (typeof sessionStorage !== 'undefined') sessionStorage.clear()
cleanup()
})