AI Hints
Home›Angular Tutorial›toSignal(), Why Test and Testing a Component
Angular · Lesson 104 of 120

Why Test

Catch mistakes early.

⏱ 2 min read▶ Video at 2:05:39🎓 Free
Watch this lesson in the Angular courseWatch on YouTube ↗Full Angular course

Every change to an app can break something that used to work. Clicking through every page, by hand, after every change, is slow. Tests check for us, in seconds.

  • Changes break things
  • Checking by hand is slow
  • Tests check for us

What a test is

A test is code, that uses your code, and checks the result. Describe groups related tests. It is one test, with a name that says what should happen. And expect checks that a value is what it should be.

keyvalue
describe('App', ...)a group of tests
it('shows the name', ...)one test
expect(x).toBe(y)a check
Spec fileapp.spec.ts

Running tests

Ng test runs every spec file in the project. Angular uses a test runner called Vitest. It reports each test as passed, or failed, with the reason.

PartWhat it is
*.spec.tsfiles with tests
ng testruns them all
Vitestthe test runner
✓ / ×passed / failed

Summary

Tests are code that checks your code, with describe, it, and expect, run by ng test. Next, testing a component.

Key takeaways
  • describe, it
  • expect()
  • ng test
Next up: Testing a Component — check what users see