Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/app/dashboard/stats/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import DashboardStatsPage from './page';

vi.mock('@/components/DashboardStatsClient', () => ({
default: () => <div data-testid="mock-dashboard-stats-client">Stats Client</div>
}));
Comment on lines +1 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the general rules, TypeScript functions and mock implementations should have explicit return types to maintain type safety and API clarity. Please add an explicit return type (e.g., ReactElement) to the mock implementation of DashboardStatsClient.

Suggested change
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import DashboardStatsPage from './page';
vi.mock('@/components/DashboardStatsClient', () => ({
default: () => <div data-testid="mock-dashboard-stats-client">Stats Client</div>
}));
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import type { ReactElement } from 'react';
import DashboardStatsPage from './page';
vi.mock('@/components/DashboardStatsClient', () => ({
default: (): ReactElement => <div data-testid="mock-dashboard-stats-client">Stats Client</div>
}));
References
  1. In TypeScript, ensure functions and mock implementations have explicit return types and use async functions for mocks returning Promises to maintain type safety and readability.


describe('DashboardStatsPage', () => {
it('renders the DashboardStatsClient component', () => {
render(<DashboardStatsPage />);
expect(screen.getByTestId('mock-dashboard-stats-client')).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
"src/components/SkillsCard.tsx",
"src/components/LayoutEditor.tsx",
"src/lib/rateLimit.ts",
"src/app/dashboard/stats/page.tsx",
],
thresholds: {
lines: 80,
Expand Down
Loading