-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbun-test-setup.ts
More file actions
53 lines (51 loc) · 1.49 KB
/
bun-test-setup.ts
File metadata and controls
53 lines (51 loc) · 1.49 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
import { mock } from 'bun:test';
import { GlobalWindow } from 'happy-dom';
const win = new GlobalWindow();
global.window = win as any;
global.document = win.document as any;
global.navigator = win.navigator as any;
global.localStorage = win.localStorage as any;
global.addEventListener = win.addEventListener.bind(win) as any;
global.removeEventListener = win.removeEventListener.bind(win) as any;
global.dispatchEvent = win.dispatchEvent.bind(win) as any;
global.StorageEvent = win.StorageEvent as any;
// Mock dependencies that cause side effects or fail on static assets imports
mock.module('@/services/api', () => ({
api: {},
}));
mock.module('@/services/request', () => ({
getToken: () => '',
setToken: () => {},
RequestError: class extends Error {},
default: {},
}));
mock.module('@/assets/logo-h.svg', () => ({
default: 'logo',
ReactComponent: () => null,
}));
mock.module('@/assets/logo.png', () => ({
default: 'logo.png',
}));
mock.module('react-router-dom', () => ({
createHashRouter: () => ({
state: { location: { search: '', pathname: '' } },
navigate: () => {},
}),
redirect: () => {},
useNavigate: () => {},
useRouteError: () => {},
isRouteErrorResponse: () => false,
Link: () => null,
NavLink: () => null,
Outlet: () => null,
useLocation: () => ({
pathname: '',
search: '',
hash: '',
state: null,
key: 'default',
}),
useSearchParams: () => [new URLSearchParams(), () => {}],
useLoaderData: () => null,
useActionData: () => null,
}));