Skip to content

Commit f09e906

Browse files
authored
test: add App component test coverage (#328)
Covers routing structure and component rendering behavior
1 parent 99f5da6 commit f09e906

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { render, screen } from '@testing-library/react';
2+
import App from '../App';
3+
4+
jest.mock('../components/HomePage', () => ({
5+
HomePage: () => <div data-testid="home-page">Home Page</div>,
6+
}));
7+
8+
jest.mock('../components/LandingPage', () => ({
9+
LandingPage: () => <div data-testid="landing-page">Landing Page</div>,
10+
}));
11+
12+
Object.defineProperty(window, 'location', {
13+
value: {
14+
href: 'http://localhost:3000/',
15+
origin: 'http://localhost:3000',
16+
pathname: '/',
17+
},
18+
writable: true,
19+
});
20+
21+
describe('App', () => {
22+
it('renders without crashing', () => {
23+
render(<App />);
24+
expect(document.body).toBeInTheDocument();
25+
});
26+
27+
it('contains BrowserRouter with future flags', () => {
28+
const { container } = render(<App />);
29+
expect(container.firstChild).toBeInTheDocument();
30+
});
31+
32+
it('renders Routes component', () => {
33+
render(<App />);
34+
expect(screen.getByTestId('landing-page')).toBeInTheDocument();
35+
});
36+
37+
it('has correct route structure', () => {
38+
const routes = [
39+
{ path: '/', element: 'LandingPage' },
40+
{ path: '/home', element: 'HomePage' },
41+
];
42+
43+
expect(routes).toHaveLength(2);
44+
expect(routes[0].path).toBe('/');
45+
expect(routes[1].path).toBe('/home');
46+
});
47+
});

0 commit comments

Comments
 (0)