Skip to content

Commit c911a69

Browse files
committed
frontend: fix linting
1 parent aff172e commit c911a69

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

frontend/src/components/__tests__/alert.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { render, screen } from '@testing-library/preact';
2-
import { fireEvent } from '@testing-library/preact';
1+
import { render, screen, fireEvent } from '@testing-library/preact';
32
import { describe, it, expect, vi, beforeEach } from 'vitest';
43

54
// Helper to flush timers when using setTimeout
@@ -23,7 +22,7 @@ describe('Alert component & showAlert', () => {
2322

2423
it('suppresses alert containing Failed to fetch', async () => {
2524
const real = await vi.importActual<typeof import('../Alert')>('../Alert');
26-
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
25+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
2726
real.showAlert('Failed to fetch resource', 'danger');
2827
render(<real.ErrorAlert />);
2928
expect(screen.queryByText('Failed to fetch resource')).toBeNull();

frontend/src/test-setup.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,26 @@ vi.mock('react-bootstrap', () => {
255255

256256
// Separate mock for direct 'react-bootstrap/Alert' import used in Alert component
257257
vi.mock('react-bootstrap/Alert', () => {
258-
const { h } = require('preact');
259-
const Alert = ({ children, variant, dismissible, onClose }: { children?: any; variant?: string; dismissible?: boolean; onClose?: () => void; }) =>
258+
interface MockAlertProps {
259+
children?: ComponentChildren;
260+
variant?: string;
261+
dismissible?: boolean;
262+
onClose?: () => void;
263+
}
264+
265+
interface AlertComponent {
266+
(props: MockAlertProps): ReturnType<typeof h>;
267+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
268+
Heading?: (props: { children?: ComponentChildren }) => any;
269+
}
270+
// Define without annotation first to prevent TS from narrowing attributes incompatibly
271+
const AlertFn = ({ children, variant, dismissible, onClose }: MockAlertProps) =>
260272
h('div', { className: `alert alert-${variant || 'primary'}` }, [
261273
children,
262274
dismissible && h('button', { 'data-testid': 'close-alert', onClick: onClose }, '×')
263275
]);
264-
(Alert as any).Heading = ({ children }: { children?: any }) => h('h4', { 'data-testid': 'alert-heading' }, children);
276+
const Alert = AlertFn as AlertComponent;
277+
Alert.Heading = ({ children }: { children?: ComponentChildren }) => h('h4', { 'data-testid': 'alert-heading' }, children);
265278
return { default: Alert };
266279
});
267280

0 commit comments

Comments
 (0)