mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Introduced new documentation files for state management and testing guidelines to enhance developer understanding and best practices. - 📚 **Docs**: Added state management guidelines with local and global state recommendations - 📚 **Docs**: Created testing guidelines including unit testing requirements and best practices - 📚 **Docs**: Updated project structure documentation for clarity
1.9 KiB
1.9 KiB
Testing Instructions
Framework and Tools
- Use Jest as the testing framework.
- For unit tests, utilize Spectator to simplify Angular component testing.
Guidelines
- Error Case Testing: Ensure all edge cases and error scenarios are thoroughly tested.
- Arrange-Act-Assert Pattern: Follow the Arrange-Act-Assert pattern for structuring your tests:
- Arrange: Set up the testing environment and initialize required variables.
- Act: Execute the functionality being tested.
- Assert: Verify the expected outcomes.
Best Practices
- Write clear and descriptive test names.
- Ensure tests are isolated and do not depend on each other.
- Mock external dependencies to avoid side effects.
- Aim for high code coverage without compromising test quality.
Example Test Structure
// Example using Jest and Spectator
import { createComponentFactory, Spectator } from '@ngneat/spectator';
import { MyComponent } from './my-component.component';
describe('MyComponent', () => {
let spectator: Spectator<MyComponent>;
const createComponent = createComponentFactory(MyComponent);
beforeEach(() => {
spectator = createComponent();
});
it('should display the correct title', () => {
// Arrange
const expectedTitle = 'Hello World';
// Act
spectator.component.title = expectedTitle;
spectator.detectChanges();
// Assert
expect(spectator.query('h1')).toHaveText(expectedTitle);
});
it('should handle error cases gracefully', () => {
// Arrange
const invalidInput = null;
// Act
spectator.component.input = invalidInput;
// Assert
expect(() => spectator.component.processInput()).toThrowError('Invalid input');
});
});