-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTests.ts
82 lines (76 loc) · 2.01 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
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
// setupTests.ts
import '@testing-library/jest-dom'
import { vi } from 'vitest'
import type { Navigation, Page } from '@sveltejs/kit'
import { readable } from 'svelte/store'
import * as environment from '$app/environment'
import * as navigation from '$app/navigation'
import * as stores from '$app/stores'
vi.mock('$lib/stores/media', () => ({
media: readable({
sm: true,
md: true,
lg: true,
xl: true,
'2xl': true,
}),
}))
// Mock SvelteKit runtime module $app/environment
vi.mock('$app/environment', (): typeof environment => ({
browser: false,
dev: true,
building: false,
version: 'any',
}))
// Mock SvelteKit runtime module $app/navigation
vi.mock('$app/navigation', (): typeof navigation => ({
afterNavigate: () => vi.fn(),
beforeNavigate: () => vi.fn(),
disableScrollHandling: () => vi.fn(),
goto: () => Promise.resolve(),
invalidate: () => Promise.resolve(),
invalidateAll: () => Promise.resolve(),
preloadData: () => Promise.resolve(),
preloadCode: () => Promise.resolve(),
}))
// Mock SvelteKit runtime module $app/stores
vi.mock('$app/stores', (): typeof stores => {
const getStores: typeof stores.getStores = () => {
const navigating = readable<Navigation | null>(null)
const page = readable<Page>({
url: new URL('http://localhost'),
params: {},
route: {
id: null,
},
status: 200,
error: null,
data: {},
form: undefined,
})
const updated = { subscribe: readable(false).subscribe, check: async () => false }
return { navigating, page, updated }
}
const page: typeof stores.page = {
subscribe(fn) {
return getStores().page.subscribe(fn)
},
}
const navigating: typeof stores.navigating = {
subscribe(fn) {
return getStores().navigating.subscribe(fn)
},
}
const updated: typeof stores.updated = {
subscribe(fn) {
return getStores().updated.subscribe(fn)
},
check: async () => false,
}
return {
getStores,
navigating,
page,
updated,
}
})