Skip to content

Commit 78a360f

Browse files
authored
test(template): add empty fallback coverage (JhaSourav07#3093)
## Description Fixes JhaSourav07#2863 Added isolated unit tests for `app/template.tsx` focusing on edge cases, empty children handling, and fallback rendering stability. ### Changes - Added `app/template.empty-fallback.test.tsx` - Mocked `framer-motion` to isolate component behavior - Verified the template renders successfully with `null` children - Tested rendering behavior with `undefined` children - Confirmed empty fragments do not cause runtime or hydration issues - Verified wrapper structure is preserved when no content is provided - Tested normal rendering with valid child content - Improved coverage around empty states and fallback rendering scenarios ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview N/A (test-only changes) ## Checklist before requesting a review: - [x] I have read the `CONTRIBUTING.md` file. - [x] I have tested these changes locally. - [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 starred the repo. - [x] I have made sure that I have only one commit to merge in this PR. - [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no visual changes made). - [ ] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 0783fae + 630d9ea commit 78a360f

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// app/template.empty-fallback.test.tsx
2+
3+
import { describe, expect, it, vi } from 'vitest';
4+
import { render, screen } from '@testing-library/react';
5+
import '@testing-library/jest-dom';
6+
7+
vi.mock('framer-motion', () => ({
8+
motion: {
9+
div: ({ children }: { children?: React.ReactNode }) => (
10+
<div data-testid="motion-wrapper">{children}</div>
11+
),
12+
},
13+
}));
14+
15+
import Template from './template';
16+
17+
describe('Template Empty & Missing Input Fallbacks', () => {
18+
it('renders successfully with null children', () => {
19+
render(<Template>{null}</Template>);
20+
21+
expect(screen.getByTestId('motion-wrapper')).toBeInTheDocument();
22+
});
23+
24+
it('renders successfully with undefined children', () => {
25+
render(<Template>{undefined}</Template>);
26+
27+
expect(screen.getByTestId('motion-wrapper')).toBeInTheDocument();
28+
});
29+
30+
it('renders successfully with an empty fragment', () => {
31+
render(
32+
<Template>
33+
<></>
34+
</Template>
35+
);
36+
37+
expect(screen.getByTestId('motion-wrapper')).toBeInTheDocument();
38+
});
39+
40+
it('preserves wrapper structure when no content is provided', () => {
41+
render(<Template>{null}</Template>);
42+
43+
const wrapper = screen.getByTestId('motion-wrapper');
44+
45+
expect(wrapper).toBeInTheDocument();
46+
expect(wrapper.childElementCount).toBe(0);
47+
});
48+
49+
it('renders provided content correctly', () => {
50+
render(
51+
<Template>
52+
<div>Fallback Content</div>
53+
</Template>
54+
);
55+
56+
expect(screen.getByText('Fallback Content')).toBeInTheDocument();
57+
});
58+
});

0 commit comments

Comments
 (0)