Angular › Testing with Jasmine & Karma

What is the difference between a unit test and a component test in an Angular app?

Beginner

Answer

A unit test checks a small, isolated piece of logic, like a single function or service method, completely on its own, often without needing Angular's TestBed at all. A component test renders an actual component using TestBed and checks that it behaves correctly, often simulating user interactions like clicks, giving you confidence that the component works as a whole.
// Unit test, testing a plain function, no TestBed needed
it('formats price correctly', () => {
  expect(formatPrice(9.5)).toBe('$9.50');
});

// Component test, testing a full rendered component using TestBed
it('displays formatted price', () => {
  fixture.detectChanges();
  expect(fixture.nativeElement.textContent).toContain('$9.50');
});
Real-world example A team writes a quick unit test for their price formatting function, and a separate component test using TestBed to confirm a PriceTag component actually displays that formatted price correctly to the user on screen.

Common follow-ups: Why is it useful to have both kinds of tests instead of relying on just one type?;How much of an app's total test coverage should typically be unit tests versus component tests?