Skip to content

Commit 58c0a7c

Browse files
committed
test: prevent next/image fill prop warnings in mocks
1 parent 3bbb5cc commit 58c0a7c

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)