Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsAngular’s testing utilities center on two things: TestBed, which builds an isolated test environment and creates or injects the thing under test, and ComponentFixture, the handle for a component that TestBed created. Around them sit helpers for asynchronous work, HTTP simulation and CDK component harnesses. The biggest current pitfall is the runner. Angular’s testing overview describes Vitest as the default for new CLI projects, while the Testing Utility APIs guide is still being updated and retains some Karma/Jasmine framing. Match every example to your project’s actual runner and Angular version.
TestBed: configure, create, inject
Per the utility guide, TestBed configures the testing environment, lets you provide or override dependencies, creates components and retrieves services.
- Configure:
TestBed.configureTestingModulesets imports and providers. Use overrides when a test needs adjusted metadata. - Create or inject:
TestBed.createComponentfor components,TestBed.injectfor services. - Fresh state: configure in
beforeEachso each test starts clean. - Async compilation: compile asynchronously when resources, such as deferred blocks, load asynchronously.
- Freeze rule: once a component is created or something is injected, configuration is frozen for that spec. Finish all setup and overrides first.
ComponentFixture and what to test
A component is its class working with its template. The component testing basics page frames the choice: if rendering, input, events or parent/child integration matter, create the component through TestBed and assert observable DOM behavior via the fixture. If DOM interaction is irrelevant, testing the class alone is simpler.
Choosing an async utility
| Utility | Purpose | Runner constraint |
|---|---|---|
waitForAsync |
Runs the test in an async test zone and completes when tracked work finishes | Zone.js setup |
fakeAsync |
Runs code in a special zone with controlled fake time | Requires Zone.js; cannot be used with Vitest |
tick(ms) |
Advances virtual time and runs eligible timers inside fakeAsync |
Same as fakeAsync |
flushMicrotasks() |
Processes queued microtasks inside fakeAsync |
Same as fakeAsync |
These are documented in Zone.js Testing Utilities, and the fakeAsync API reference carries the Vitest warning. Angular’s component-testing guidance no longer recommends fakeAsync for typical current tests and points to native async testing or the runner’s fake timers. The docs mention a Vitest patch for Zone.js integration, but that doesn’t override the reference’s statement that fakeAsync can’t be used with Vitest; treat it as a compatibility constraint, not a recommended combination.
#1 Best Overall
To decide, ask three questions: which runner you use, whether the code depends on timers, promises or both, and whether a native async/await flow is clear without a virtual clock. In compatible Zone.js setups, a healthy test should finish without unexpected queued tasks; the Zone.js utilities include ways to drain microtasks or discard periodic tasks when pending work is expected.
Testing HttpClient without a network
The HTTP testing guide replaces the real backend with a test one.
Rank #2
- Add
provideHttpClientTesting()to the test providers. - Inject
HttpTestingController. - Call the service, then use the controller to expect the request and assert on it.
- Flush a test response, and verify no unexpected requests occurred.
If you also configure HttpClient features, list provideHttpClient(...) first and provideHttpClientTesting() second; order matters.
Testing services
Per Testing services, configure TestBed with the service and replace collaborators with stubs or value providers where you need isolation, and use spies to assert interactions. For services using HttpClient, use the HTTP testing backend above rather than remote calls.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
Component harnesses for shared components
CDK component harnesses give consumers a supported interaction API so tests don’t depend on a shared component’s internal DOM. See Using component harnesses and Creating component harnesses. In a unit test, create a fixture, build a TestbedHarnessEnvironment loader from it, and call the component-specific harness methods. Harness operations generally run change detection and wait for tasks inside NgZone; explicit stabilization helpers cover animations or work scheduled outside NgZone.
Quick Recap
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




