Writing even easier tests with Angular CDK component harnesses
When writing tests for components, there might be scenarios where you’d want to interact with the DOM elements. Now, this can already be achieved by using the fixture.debugElement.query
method to find the element, using a selector and then triggering events on it. However, that means maintaining the DOM queries for different platforms, knowing the identifiers of all the selectors, and then exposing all of that in the tests. And this is even worse if we’re talking about an Angular library. It certainly isn’t necessary for each developer who interacts with my library to know all the element selectors in order to write tests. Only the author of the library should know that much to respect encapsulation. Luckily, we have the component harnesses from the Angular CDK team, which were released with Angular 9 along with the IVY compiler. And they’ve led by example, by providing component harnesses for...