0Pricing
Angular Academy · Lesson

TestBed and Component Fixtures

Configure and create components in tests.

Why TestBed Exists

Angular components depend on the framework: dependency injection, change detection, and the template compiler. To test them in isolation you need a tiny Angular environment. TestBed is Angular's primary testing utility that builds this environment for each test.

It configures a temporary NgModule, compiles your component, and gives you a handle to interact with it.

configureTestingModule

TestBed.configureTestingModule() declares what your test needs: the component under test, its providers, and any imports. For standalone components you put the component itself in imports.

import { TestBed } from '@angular/core/testing';
import { CounterComponent } from './counter.component';

beforeEach(() => {
  TestBed.configureTestingModule({
    imports: [CounterComponent],
  });
});

All lessons in this course

  1. TestBed and Component Fixtures
  2. Testing Inputs, Outputs, and DOM
  3. Mocking Services and Dependencies
  4. Testing Signals and Async Code
← Back to Angular Academy