Test your components with Angular Material’s component harnesses!

How and why to use Angular materials component harness to write reliable, stable and readable component tests

Kevin Kreuzer
8 min readFeb 24, 2020

Simultaneously to the Angular 9 release, a new version of the Material component library was released. This release includes an absolute highlight feature, Angular Material test harnesses.

Testing in Angular

Good tests are the backbone of every application. They ensure that our app runs the way we expect it. Moreover, a robust test suite facilitates refactorings. Reliable tests allow us to change things under the hood without affecting the behavior.

In Angular, we distinguish between different types of tests; unit tests, component tests (integration tests) and end to end tests.

The testing pyramid for Angular applications

Unit tests are the most straightforward tests to write; they simply test functions of our TypeScript code. Component- and End to end tests on the other side are a little bit harder. They don’t only test the TypeScript code, but also the template, which may include third-party libraries such as…

--

--

Kevin Kreuzer

Passionate freelance frontend engineer. ❤️ Always eager to learn, share and expand knowledge.