-
Notifications
You must be signed in to change notification settings - Fork 0
/
vitest.setup.mts
52 lines (46 loc) · 1.07 KB
/
vitest.setup.mts
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
import { cleanup } from '@testing-library/react'
import { vi, afterEach } from 'vitest'
export const viMockNextNavigation = () => {
vi.mock('next/navigation', () => {
return {
__esModule: true,
useParams: () => ({ locale: 'en' }),
useSearchParams: () => ({ query: '{"website":"without"}' }),
usePathname: () => '/en/bookshops'
}
})
}
export const viMockReactI18next = () => {
vi.mock('react-i18next', () => {
return {
__esModule: true,
useTranslation: () => ({
t: (translation: string) => translation,
i18n: {
resolvedLanguage: 'en',
changeLanguage: () => new Promise(() => {}),
}
}),
initReactI18next: {
type: '3rdParty',
init: () => {},
},
}
})
}
export const viMockExenv = (canUseDom: boolean) => {
vi.mock('exenv', () => {
return {
__esModule: true,
canUseDOM: () => canUseDom
}
})
}
export const viMockStateReset = () => {
vi.clearAllMocks()
vi.resetAllMocks()
vi.restoreAllMocks()
}
afterEach(() => {
cleanup()
})