mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
- feat(remission-shared-produt-shelf-meta-info): Intermediate commit. - feat(remission-shared-product-shelf-meta-info): improve template structure and data attributes - feat(remission-list-item): add product shelf meta info and improve E2E selectors Refs: #4769, #5196
2.4 KiB
2.4 KiB
Testing Instructions
Framework and Tools
- Vitest is the recommended testing framework.
Vitest Documentation (latest) - Jest and Spectator are deprecated.
Do not use them for new tests. Existing tests should be migrated to Vitest where possible.
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 Vitest (Jest and Spectator are deprecated)
import { describe, it, expect, beforeEach } from 'vitest';
import { render } from '@testing-library/angular';
import { MyComponent } from './my-component.component';
describe('MyComponent', () => {
let component: MyComponent;
beforeEach(async () => {
const { fixture } = await render(MyComponent);
component = fixture.componentInstance;
});
it('should display the correct title', async () => {
// Arrange
const expectedTitle = 'Hello World';
// Act
component.title = expectedTitle;
// If using Angular, trigger change detection:
// fixture.detectChanges();
// Assert
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toBe(expectedTitle);
});
it('should handle error cases gracefully', () => {
// Arrange
const invalidInput = null;
// Act
component.input = invalidInput;
// Assert
expect(() => component.processInput()).toThrowError('Invalid input');
});
});
Additional Resources
- Vitest Documentation (latest)
- Vitest Official Guide
- Testing Library for Angular
- Jest and Spectator documentation are deprecated