Files
ISA-Frontend/.github/testing-instructions.md
Nino Righi 5f74c6ddf8 Merged PR 1878: Refs: #4769, #5196
- 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
2025-07-11 19:53:56 +00:00

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

  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

// 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