Files
raceplanner/openspec/changes/add-tests/specs/frontend-unit-tests/spec.md
T
Denis Urs Rudolph 571fe5bc7c Add comprehensive test suite infrastructure
- Create backend xUnit test project with Moq and FluentAssertions
- Add test utilities: TestDataFactory, MockHttpContext, TestUserClaims
- Create AuthControllerTests with comprehensive auth scenarios
- Install Jest and React Testing Library for frontend
- Configure jest.config.ts and jest.setup.ts with Next.js support
- Add test scripts to package.json
2026-04-05 22:16:44 +02:00

50 lines
2.0 KiB
Markdown

## ADDED Requirements
### Requirement: Jest is configured
The system SHALL have Jest configured for the Next.js frontend with TypeScript support.
#### Scenario: Jest runs TypeScript tests
- **WHEN** a test file with `.test.ts` or `.test.tsx` extension is executed
- **THEN** Jest SHALL compile and run TypeScript tests successfully
#### Scenario: Jest runs in Next.js environment
- **WHEN** tests import Next.js modules or use Next.js APIs
- **THEN** the test environment SHALL provide necessary Next.js mocks and configuration
### Requirement: React Testing Library is configured
The system SHALL have React Testing Library configured for component testing.
#### Scenario: Components can be rendered in tests
- **WHEN** a React component is rendered using render() from RTL
- **THEN** the component SHALL render in a virtual DOM for testing
#### Scenario: User interactions can be simulated
- **WHEN** test code uses userEvent or fireEvent
- **THEN** user interactions SHALL be simulated on rendered components
### Requirement: Custom hooks can be tested
The system SHALL provide utilities for testing custom React hooks.
#### Scenario: Hook can be tested with renderHook
- **WHEN** a custom hook is tested using renderHook utility
- **THEN** the hook SHALL execute and return values can be asserted
#### Scenario: Hook state changes can be awaited
- **WHEN** a hook performs async operations
- **THEN** the test SHALL be able to wait for state updates with waitFor utility
### Requirement: API mocking is available
The system SHALL provide utilities for mocking HTTP requests in frontend tests.
#### Scenario: API calls can be mocked
- **WHEN** components make HTTP requests using fetch or axios
- **THEN** the test SHALL be able to mock responses using MSW or jest-fetch-mock
#### Scenario: Loading states can be tested
- **WHEN** components are fetching data
- **THEN** the test SHALL verify loading states are rendered correctly
#### Scenario: Error states can be tested
- **WHEN** API calls fail
- **THEN** the test SHALL verify error handling and error messages