Testing Guide
Complete guide to testing in Lager Guru.
Overview
Testing ensures code quality and prevents regressions.
Testing Types
Unit Tests
Test individual functions and components in isolation.
Integration Tests
Test interactions between components and services.
E2E Tests
Test complete user workflows (to be implemented).
Running Tests
bash
# Run all tests
npm test
# Run tests in watch mode
npm test -- --watch
# Run tests with coverage
npm test -- --coverageWriting Tests
Component Tests
typescript
import { render, screen } from '@testing-library/react'
import { MyComponent } from './MyComponent'
test('renders component', () => {
render(<MyComponent />)
expect(screen.getByText('Hello')).toBeInTheDocument()
})Hook Tests
typescript
import { renderHook } from '@testing-library/react'
import { useMyHook } from './useMyHook'
test('hook returns expected value', () => {
const { result } = renderHook(() => useMyHook())
expect(result.current).toBeDefined()
})Test Coverage
Aim for:
- 80%+ code coverage
- All critical paths tested
- Edge cases covered
Best Practices
- Write tests before fixing bugs
- Test user interactions
- Mock external dependencies
- Keep tests fast and isolated
- Use descriptive test names