Lesson 29 / 30
Testing a Component
TestBed sets up an isolated environment to test a component.
What TestBed does
TestBed creates a mini Angular module for the test, letting you instantiate a component with real or fake dependencies and inspect its rendered output.
A minimal test
This test creates the component, triggers change detection, and checks a value on the instance.
describe('CounterComponent', () => {
it('increments the count', () => {
const fixture = TestBed.createComponent(CounterComponent);
const component = fixture.componentInstance;
component.increment();
fixture.detectChanges();
expect(component.count()).toBe(1);
});
});