Skip to main content

Testing

Unit Tests

Run unit tests via Karma:

npm test

Tests are written using Jasmine and located alongside components:

  • *.spec.ts files

End-to-End Tests

Run e2e tests via Protractor:

npm run e2e

E2E tests are located in the e2e/ directory.

Test Configuration

  • Karma: karma.conf.js
  • Protractor: e2e/protractor.conf.js
  • TypeScript: tsconfig.spec.json

Writing Tests

Example component test:

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

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

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

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

  it('should load cart items', () => {
    component.loadCart();
    expect(component.cartItems.length).toBeGreaterThan(0);
  });
});