1 Frontend Testing
Jan K9f edited this page 2025-06-04 09:36:55 +02:00

Frontend Testing

This page provides guidelines and best practices for testing the Angular frontend of the Casino application.

Unit Testing

Unit tests for Angular components, services, and pipes are written using Jasmine and Karma.

Running Unit Tests

# Run all unit tests
npm run test

# Run tests with coverage
npm run test:coverage

Component Testing

Component tests verify that components render correctly and respond to user interactions as expected.

describe('GameComponent', () => {
  let component: GameComponent;
  let fixture: ComponentFixture<GameComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [GameComponent]
    }).compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(GameComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

End-to-End Testing

E2E tests are written using Cypress to test the application as a whole.

Running E2E Tests

# Open Cypress test runner
npm run e2e

# Run all E2E tests headlessly
npm run e2e:ci

Mocking Services

Use Angular's HttpClientTestingModule to mock HTTP requests:

TestBed.configureTestingModule({
  imports: [HttpClientTestingModule],
  providers: [GameService]
});

Test Coverage

Aim for at least 80% code coverage for all frontend components.

Best Practices

  1. Test component outputs and inputs
  2. Mock external services
  3. Test form validation
  4. Verify component state changes
  5. Test error handling