Skip to content

Commit aebfe1a

Browse files
committed
fix: prevent Framer Motion props from reaching DOM elements
1 parent ea059a6 commit aebfe1a

4 files changed

Lines changed: 86 additions & 8 deletions

File tree

app/components/FeatureCard.test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
13
import { describe, it, expect, vi } from 'vitest';
24
import { render, screen } from '@testing-library/react';
35
import { FeatureCard } from './FeatureCard';
@@ -6,9 +8,18 @@ import { FeatureCard } from './FeatureCard';
68
// don't mean anything to jsdom, so we stub motion.div with a plain div.
79
vi.mock('framer-motion', () => ({
810
motion: {
9-
div: ({ children, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
10-
<div {...props}>{children}</div>
11-
),
11+
div: ({
12+
children,
13+
whileHover,
14+
whileTap,
15+
whileInView,
16+
initial,
17+
animate,
18+
exit,
19+
transition,
20+
viewport,
21+
...props
22+
}: any) => <div {...props}>{children}</div>,
1223
},
1324
}));
1425

app/page.test.tsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
23
/* eslint-disable @next/next/no-img-element, jsx-a11y/alt-text */
34
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
45
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
@@ -31,17 +32,57 @@ vi.mock('next/link', () => ({
3132
// Mock framer-motion
3233
vi.mock('framer-motion', () => ({
3334
motion: {
34-
div: ({ children, className, ...props }: any) => (
35+
div: ({
36+
children,
37+
className,
38+
whileHover,
39+
whileTap,
40+
whileInView,
41+
initial,
42+
animate,
43+
exit,
44+
transition,
45+
viewport,
46+
layoutId,
47+
...props
48+
}: any) => (
3549
<div className={className} data-testid="motion-div" {...props}>
3650
{children}
3751
</div>
3852
),
39-
p: ({ children, className, ...props }: any) => (
53+
p: ({
54+
children,
55+
className,
56+
whileHover,
57+
whileTap,
58+
whileInView,
59+
initial,
60+
animate,
61+
exit,
62+
transition,
63+
viewport,
64+
layoutId,
65+
...props
66+
}: any) => (
4067
<p className={className} data-testid="motion-p" {...props}>
4168
{children}
4269
</p>
4370
),
44-
a: ({ children, className, href, ...props }: any) => (
71+
a: ({
72+
children,
73+
className,
74+
href,
75+
whileHover,
76+
whileTap,
77+
whileInView,
78+
initial,
79+
animate,
80+
exit,
81+
transition,
82+
viewport,
83+
layoutId,
84+
...props
85+
}: any) => (
4586
<a href={href} className={className} data-testid="motion-a" {...props}>
4687
{children}
4788
</a>

components/dashboard/AIInsights.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
23
import { describe, it, expect, vi, beforeEach } from 'vitest';
34
import { render, screen } from '@testing-library/react';
45
import AIInsights from './AIInsights';
@@ -7,7 +8,19 @@ import type { AIInsight } from '@/types/dashboard';
78
// Mock framer-motion
89
vi.mock('framer-motion', () => ({
910
motion: {
10-
div: ({ children, ...props }: any) => (
11+
div: ({
12+
children,
13+
whileHover,
14+
whileTap,
15+
whileInView,
16+
initial,
17+
animate,
18+
exit,
19+
transition,
20+
viewport,
21+
layoutId,
22+
...props
23+
}: any) => (
1124
<div {...props} data-testid="motion-div">
1225
{children}
1326
</div>

components/dashboard/StatsCard.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
23
import { describe, it, expect, vi, beforeEach } from 'vitest';
34
import { render, screen } from '@testing-library/react';
45
import StatsCard from './StatsCard';
56

67
// Mock framer-motion
78
vi.mock('framer-motion', () => ({
89
motion: {
9-
div: ({ children, ...props }: any) => (
10+
div: ({
11+
children,
12+
whileHover,
13+
whileTap,
14+
whileInView,
15+
initial,
16+
animate,
17+
exit,
18+
transition,
19+
viewport,
20+
layoutId,
21+
...props
22+
}: any) => (
1023
<div {...props} data-testid="motion-div">
1124
{children}
1225
</div>

0 commit comments

Comments
 (0)