-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.ts
More file actions
92 lines (84 loc) · 2.37 KB
/
jest.setup.ts
File metadata and controls
92 lines (84 loc) · 2.37 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
87
88
89
90
91
92
/* eslint-disable @typescript-eslint/no-require-imports */
import '@testing-library/jest-dom';
// Framer-motion props to filter out from DOM elements
const framerMotionProps = [
'whileTap',
'whileHover',
'whileFocus',
'whileDrag',
'whileInView',
'onTap',
'onTapStart',
'onTapCancel',
'onHoverStart',
'onHoverEnd',
'onDrag',
'onDragStart',
'onDragEnd',
'animate',
'initial',
'exit',
'variants',
'transition',
'layout',
'layoutId',
'drag',
'dragConstraints',
'dragElastic',
'dragMomentum',
'dragSnapToOrigin',
'dragTransition',
'onPan',
'onPanStart',
'onPanEnd',
'onAnimationStart',
'onAnimationComplete',
];
// Helper to filter framer-motion props
function filterMotionProps<T extends Record<string, unknown>>(props: T): Partial<T> {
const filtered: Record<string, unknown> = {};
for (const [key, value] of Object.entries(props)) {
if (!framerMotionProps.includes(key)) {
filtered[key] = value;
}
}
return filtered as Partial<T>;
}
// Mock framer-motion to avoid animation issues in tests
jest.mock('framer-motion', () => {
const React = require('react');
const MotionA = React.forwardRef(function MotionA(
{ children, ...props }: Record<string, unknown> & { children?: React.ReactNode },
ref: React.Ref<HTMLAnchorElement>
) {
const filteredProps = filterMotionProps(props);
return React.createElement('a', { ...filteredProps, ref }, children);
});
const MotionDiv = React.forwardRef(function MotionDiv(
{ children, ...props }: Record<string, unknown> & { children?: React.ReactNode },
ref: React.Ref<HTMLDivElement>
) {
const filteredProps = filterMotionProps(props);
return React.createElement('div', { ...filteredProps, ref }, children);
});
const MotionSpan = React.forwardRef(function MotionSpan(
{ children, ...props }: Record<string, unknown> & { children?: React.ReactNode },
ref: React.Ref<HTMLSpanElement>
) {
const filteredProps = filterMotionProps(props);
return React.createElement('span', { ...filteredProps, ref }, children);
});
return {
motion: {
a: MotionA,
div: MotionDiv,
span: MotionSpan,
},
AnimatePresence: ({ children }: { children: React.ReactNode }) => children,
};
});
// Mock navigator.vibrate for haptic feedback tests
Object.defineProperty(navigator, 'vibrate', {
value: jest.fn(),
writable: true,
});