# Testing Instructions ## Framework and Tools - **Vitest** is the recommended testing framework. [Vitest Documentation (latest)](https://context7.com/vitest-dev/vitest/llms.txt?topic=getting+started) - **Jest** and **Spectator** are **deprecated**. Do not use them for new tests. Existing tests should be migrated to Vitest where possible. ## Guidelines 1. **Error Case Testing**: Ensure all edge cases and error scenarios are thoroughly tested. 2. **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 ```typescript // 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)](https://context7.com/vitest-dev/vitest/llms.txt?topic=getting+started) - [Vitest Official Guide](https://vitest.dev/guide/) - [Testing Library for Angular](https://testing-library.com/docs/angular-testing-library/intro/) - **Jest** and **Spectator** documentation are deprecated