Frontend Tests¶
Frontend tests use Jest and React Testing Library, included by default with Create React App.
Running Tests¶
With Coverage¶
Test Structure¶
client/src/
├── App.test.js # Main app smoke test
├── setupTests.js # Jest DOM setup
└── components/
└── __tests__/ # Component-level tests (optional)
Writing New Tests¶
- Create test files alongside components or in a
__tests__/directory - Use
@testing-library/reactfor rendering and querying - Mock the Supabase client for any components that use authentication
- Focus on user-visible behavior rather than implementation details
Example¶
import { render, screen } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import MyComponent from '../MyComponent';
test('displays the expected heading', () => {
render(
<BrowserRouter>
<MyComponent />
</BrowserRouter>
);
expect(screen.getByRole('heading')).toBeInTheDocument();
});
Mocking Supabase¶
Components that use the Supabase client need it mocked in tests: