A practical guide to testing and faking Angular dependencies using dependency injection tokens and the Angular testing utilities. Covers how to replace tree-shakable providers with fake values using TestBed and the inject function, including gotchas for each approach. Demonstrates testing value factories that depend on platform-specific APIs (Navigator, Location), building a fake user agent enum, and writing component tests for an IE11 deprecation banner with a custom test harness that handles setup, event simulation, and assertions.
Table of contents
Faking dependency injection tokens used in token providers Copy link Link copied!Testing value factories with dependencies Copy link Link copied!Faking dependencies in component tests Copy link Link copied!Summary Copy link Link copied!Resources Copy link Link copied!Related articles Copy link Link copied!Reviewers Copy link Link copied!Sort: