Skip to content

Commit 372de15

Browse files
authored
test(leaderboard): add error resilience coverage (JhaSourav07#3200)
## Description Fixes JhaSourav07#2758 Adds focused Vitest coverage for hydration stability, exception safety, and error resilience behavior in `components/Leaderboard.tsx`. Tests verify: * Valid contributor data renders without runtime errors * Empty contributor arrays render safely * Empty-state rendering remains hydration-safe * Minimal contributor values do not crash rendering * Repeated renders remain stable without exceptions ## Pillar * [ ] 🎨 Pillar 1 — New Theme Design * [ ] 📐 Pillar 2 — Geometric SVG Improvement * [ ] 🕐 Pillar 3 — Timezone Logic Optimization * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable — test-only change. ## Checklist before requesting a review: * [x] I have read the `CONTRIBUTING.md` file. * [ ] 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. * [x] I have started the repo. * [x] I have made sure that i have only one commit to merge in this PR. * [ ] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). * [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents dff4fc0 + a14fb00 commit 372de15

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { render } from '@testing-library/react';
2+
import type { ComponentProps, ReactNode } from 'react';
3+
import { describe, expect, it, vi } from 'vitest';
4+
import Leaderboard, { type Contributor } from './Leaderboard';
5+
6+
vi.mock('next/image', () => ({
7+
default: ({ alt = '', ...props }: ComponentProps<'img'>) => (
8+
// eslint-disable-next-line @next/next/no-img-element
9+
<img alt={alt} {...props} />
10+
),
11+
}));
12+
13+
vi.mock('framer-motion', () => ({
14+
motion: {
15+
div: ({ children, ...props }: ComponentProps<'div'> & { children?: ReactNode }) => (
16+
<div {...props}>{children}</div>
17+
),
18+
},
19+
}));
20+
21+
const contributors: Contributor[] = [
22+
{
23+
id: 1,
24+
login: 'alice',
25+
avatar_url: '/avatar.png',
26+
contributions: 100,
27+
html_url: 'https://github.com/alice',
28+
},
29+
];
30+
31+
describe('Leaderboard error resilience', () => {
32+
it('renders without crashing with valid contributor data', () => {
33+
expect(() => render(<Leaderboard contributors={contributors} />)).not.toThrow();
34+
});
35+
36+
it('renders safely with an empty contributor array', () => {
37+
expect(() => render(<Leaderboard contributors={[]} />)).not.toThrow();
38+
});
39+
40+
it('maintains stable hydration-safe rendering for empty state', () => {
41+
const { container } = render(<Leaderboard contributors={[]} />);
42+
43+
expect(container).toBeTruthy();
44+
expect(container.firstChild).not.toBeNull();
45+
});
46+
47+
it('does not throw when contributor list contains minimal values', () => {
48+
const minimalContributors: Contributor[] = [
49+
{
50+
id: 1,
51+
login: '',
52+
avatar_url: '',
53+
contributions: 0,
54+
html_url: '',
55+
},
56+
];
57+
58+
expect(() => render(<Leaderboard contributors={minimalContributors} />)).not.toThrow();
59+
});
60+
61+
it('survives repeated renders without runtime exceptions', () => {
62+
const { rerender } = render(<Leaderboard contributors={contributors} />);
63+
64+
expect(() => rerender(<Leaderboard contributors={contributors} />)).not.toThrow();
65+
});
66+
});

0 commit comments

Comments
 (0)