What you will learn
Test visible behavior, reactive state, and network boundaries with stable tests.
- TestBed creates Angular components with their providers and dependencies. Test observable behavior through the rendered DOM when that is what users depend on.
- Signals update synchronously, but effects and rendering are scheduled. Use the framework test helpers rather than arbitrary timeouts.
- HttpTestingController captures requests so a test can verify method and URL, flush a response, and assert the final UI state without a real server.
- Keep unit tests focused. A smaller number of route-level tests should cover navigation, forms, and important error paths.
How it works
1Arrange component
2Act through public UI
3Framework stabilizes
4Assert visible result
Expected result
Tests verify the counter through its DOM and complete the API call through a controlled mock response.
Common mistakes
Do not test private fields instead of behavior. Do not call a live backend in a unit test. Verify that no unexpected HTTP requests remain.
