Skip to content

Commit ea82434

Browse files
authored
test: prevent next/image fill prop warnings in mocks (JhaSourav07#3198)
## Description Fixes JhaSourav07#3197 This PR removes React warnings generated during test execution by updating the mocked `next/image` implementation used throughout the test suite. ### Problem Several test files mocked `next/image` by forwarding all received props directly to a native `<img>` element: ```tsx <img {...props} /> ``` When components rendered images using Next.js's `fill` prop: ```tsx <Image fill /> ``` the mock produced: ```tsx <img fill={true} /> ``` which caused React warnings during test execution: ```text Warning: Received `true` for a non-boolean attribute `fill`. ``` While tests continued to pass, the warnings cluttered CI logs and made it harder to identify legitimate issues. ### Fix Updated the test mocks to remove the `fill` prop before forwarding remaining props to the native `<img>` element: ```tsx const { fill, ...rest } = props; return <img {...rest} />; ``` ### Files Updated ```text page.test.tsx page.responsive-breakpoints.test.tsx page.empty-fallback.test.tsx ``` ### Result * Eliminates React DOM warnings during tests. * Keeps CI output clean and easier to review. * Better mirrors actual Next.js image behavior. * Prevents invalid attributes from being rendered in mocked components. ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A – Test-only change. No UI, SVG, or visual output modifications. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally (`localhost:3000/api/streak?user=YOUR_USERNAME`). * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors (CI will fail otherwise). * [x] My commits follow the Conventional Commits format (e.g., `feat(themes): ...`, `fix(calculate): ...`). * [ ] I have updated `README.md` if I added a new theme or URL parameter. (Not applicable) * [x] I have started the repo. * [x] I have made sure that I have only one commit to merge in this PR. * [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (No SVG changes in this PR). * [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents c329f27 + 58c0a7c commit ea82434

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

app/contributors/page.empty-fallback.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
/* eslint-disable @next/next/no-img-element, jsx-a11y/alt-text */
24
import { beforeEach, describe, expect, it, vi } from 'vitest';
35
import { render, screen } from '@testing-library/react';
46
import ContributorsPage from './page';
57

68
vi.mock('next/image', () => ({
79
__esModule: true,
8-
default: (props: any) => <img {...props} />,
10+
default: (props: any) => {
11+
const { fill, ...rest } = props || {};
12+
return <img {...rest} />;
13+
},
914
}));
1015

1116
vi.mock('next/link', () => ({

app/contributors/page.responsive-breakpoints.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
/* eslint-disable @next/next/no-img-element */
14
import { beforeEach, describe, expect, it, vi } from 'vitest';
25
import { render, screen } from '@testing-library/react';
36
import ContributorsPage from './page';
@@ -6,9 +9,10 @@ import '@testing-library/jest-dom';
69

710
vi.mock('next/image', () => ({
811
__esModule: true,
9-
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => (
10-
<img {...props} alt={props.alt || ''} />
11-
),
12+
default: (props: React.ImgHTMLAttributes<HTMLImageElement>) => {
13+
const { fill, ...rest } = props as any;
14+
return <img {...rest} alt={props.alt || ''} />;
15+
},
1216
}));
1317

1418
vi.mock('next/link', () => ({

app/page.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ vi.mock('@/components/DiscordButton', () => ({
2626
// rendered inline. The mock below keeps the import from erroring if any
2727
// other test file still imports it.
2828
vi.mock('next/image', () => ({
29-
default: (props: any) => <img {...props} />,
29+
default: (props: any) => {
30+
const { fill, ...rest } = props || {};
31+
return <img {...rest} />;
32+
},
3033
}));
3134

3235
vi.mock('next/link', () => ({

0 commit comments

Comments
 (0)