Roadmap › Angular (2 → 21) › Module: Quality and Performance
Lessons in this course (16)
15. Testing Angular apps
IntermediateMediumLesson 15 of 16
ts
describe("OrderCard", () => {
it("emits the id when clicked", async () => {
await TestBed.configureTestingModule({ imports: [OrderCard] }).compileComponents();
const fixture = TestBed.createComponent(OrderCard);
fixture.componentRef.setInput("order", { id: 7, customer: "Asha", total: 500, status: "paid" });
let emitted: number | undefined;
fixture.componentInstance.select.subscribe(id => (emitted = id));
fixture.detectChanges();
fixture.nativeElement.querySelector("button").click();
expect(emitted).toBe(7);
});
});
// Services with HTTP
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
const httpMock = TestBed.inject(HttpTestingController);
httpMock.expectOne("/api/orders").flush([]);Runners: Vitest (default in new v21 projects), Jest, or Karma + Jasmine (older projects; Karma is deprecated). Component harnesses (CDK) for Material components; Playwright/Cypress for E2E.