-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest-setup.tsx
47 lines (41 loc) · 1.18 KB
/
vitest-setup.tsx
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
import '@testing-library/jest-dom/vitest';
import { vi } from 'vitest';
import React from 'react';
// Mock Amplify configuration
vi.mock('aws-amplify', () => ({
Amplify: {
configure: vi.fn(),
},
}));
// Mock components from AWS Amplify UI React
vi.mock('@aws-amplify/ui-react', () => ({
withAuthenticator: (Component: React.ComponentType) => Component, // HOC typing
ThemeProvider: ({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
), // ThemeProvider typing
}));
// Mock AppLayout
vi.mock('@/components/Layout', () => ({
__esModule: true,
default: ({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
),
}));
// Mock SignInHeader
vi.mock('@/components/SignInHeader', () => ({
__esModule: true,
SignInHeader: () => <div>Mock SignInHeader</div>, // Named export
}));
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});