-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
86 lines (79 loc) · 2.21 KB
/
Copy pathvitest.setup.ts
File metadata and controls
86 lines (79 loc) · 2.21 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
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
import { afterEach, beforeEach, vi } from 'vitest';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
import * as React from 'react';
// Mock framer-motion to avoid animation issues in tests
vi.mock('framer-motion', () => ({
motion: new Proxy(
{},
{
get: (_target, prop) => {
const Component = React.forwardRef((props: any, ref: any) => {
const { children, ...rest } = props;
// Remove framer-motion specific props
const {
initial,
animate,
exit,
variants,
transition,
layout,
layoutId,
whileHover,
whileTap,
...cleanProps
} = rest;
return React.createElement(prop as string, { ...cleanProps, ref }, children);
});
Component.displayName = `motion.${String(prop)}`;
return Component;
},
}
),
AnimatePresence: ({ children }: { children: React.ReactNode }) => children,
}));
const localStorageMock = (() => {
let store: Record<string, string> = {};
return {
getItem: (key: string) => store[key] || null,
setItem: (key: string, value: string) => {
store[key] = value.toString();
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
store = {};
},
get length() {
return Object.keys(store).length;
},
key: (index: number) => {
const keys = Object.keys(store);
return keys[index] || null;
},
};
})();
Object.defineProperty(globalThis, 'localStorage', {
value: localStorageMock,
writable: true,
});
// Radix Select relies on pointer-capture APIs that jsdom does not implement.
if (!HTMLElement.prototype.hasPointerCapture) {
HTMLElement.prototype.hasPointerCapture = () => false;
}
if (!HTMLElement.prototype.setPointerCapture) {
HTMLElement.prototype.setPointerCapture = () => {};
}
if (!HTMLElement.prototype.releasePointerCapture) {
HTMLElement.prototype.releasePointerCapture = () => {};
}
if (!HTMLElement.prototype.scrollIntoView) {
HTMLElement.prototype.scrollIntoView = () => {};
}
beforeEach(() => {
localStorageMock.clear();
});
afterEach(() => {
cleanup();
});