0Pricing
Angular Academy · Lesson

Testing Signals and Async Code

Test reactive and asynchronous behavior.

Async Is the Hard Part of Testing

Real components do async work: timers, promises, HTTP, debounced inputs. Tests must control time so assertions run after the async work settles. Angular gives you fakeAsync, tick, and flush for deterministic time control.

Testing a Signal

A signal is read like a function. Testing it is straightforward: call the signal, assert the value; update it and assert again.

it('increments the count signal', () => {
  const fixture = TestBed.createComponent(CounterComponent);
  const c = fixture.componentInstance;
  expect(c.count()).toBe(0);
  c.increment();
  expect(c.count()).toBe(1);
});

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