Skip to content

Commit 01bdf50

Browse files
committed
test(leaderboard): add error resilience coverage
1 parent c329f27 commit 01bdf50

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)