-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests-setup.js
97 lines (87 loc) · 2.28 KB
/
tests-setup.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { beforeEach, vi } from 'vitest'
import { createRouter, createWebHistory } from 'vue-router'
import { config } from '@vue/test-utils'
import { createHead } from '@unhead/vue'
import { createPinia, setActivePinia } from "pinia"
import routes from '~pages'
setActivePinia(createPinia())
// Enables default Vue Component, such as <router-link />
// via https://test-utils.vuejs.org/guide/advanced/vue-router.html#using-a-real-router
// and https://test-utils.vuejs.org/api/#config-global
const head = createHead()
const router = createRouter({ routes, history: createWebHistory() })
config.global.plugins = [head, router]
vi.mock('axios', async (importActual) => {
const axios = await importActual()
const createMock = {
delete: vi.fn(),
get: vi.fn(),
post: vi.fn(),
head: vi.fn(),
patch: vi.fn(),
defaults: {
headers: {
common: {}
}
}
}
return {
__esModule: true,
default: {
create: vi.fn().mockReturnValue(createMock),
__createMock: createMock,
delete: vi.fn(),
get: vi.fn(),
head: vi.fn(),
post: vi.fn(),
patch: vi.fn()
},
post: vi.fn(),
AxiosError: axios.AxiosError
}
})
vi.mock('maplibre-gl', () => ({
Map: vi.fn(() => ({
addControl: vi.fn(),
on: vi.fn(),
once: vi.fn(),
remove: vi.fn(),
setGlyphs: vi.fn(),
loadImage: vi.fn(),
addSource: vi.fn(),
addLayer: vi.fn(),
fitBounds: vi.fn(),
getLayer: vi.fn(),
getSource: vi.fn(),
getZoom: vi.fn(),
getStyle: vi.fn().mockImplementation(() => ({layers: []})),
isStyleLoaded: vi.fn().mockReturnValue(true),
setLayoutProperty: vi.fn(),
resize: vi.fn(),
})),
NavigationControl: vi.fn(),
ScaleControl: vi.fn(),
}));
vi.stubGlobal('localStorage', {
getItem: vi.fn(),
setItem: vi.fn()
})
vi.mock('@vueuse/core', async (importActual) => {
const vueuse = await importActual()
return {
__esModule: true,
...vueuse,
useOnline: vi.fn().mockImplementation(() => ({ value: true }))
}
})
vi.stubGlobal('matchMedia', vi.fn(() => ({
addEventListener: vi.fn(),
matches: vi.fn().mockReturnValue(true)
})))
vi.spyOn(global, 'navigator', 'get').mockImplementation(() => ({
clipboard: {
writeText: vi.fn()
},
onLine: true
}))
beforeEach(() => vi.clearAllMocks())