4 Testing directives
This chapter covers
- Using the types of directives available in Angular
- Testing attribute and structural directives
- Using
TestMetaData
to configureTestBed
In this chapter, you’ll learn how to test directives. Directives, like components, are a way to encapsulate parts of your application as reusable chunks of code. With regard to functionality, both directives and components allow you to add behavior to the HTML in your application.
For example, let’s say your application has a table, and you want to change the background color of a row when the pointer hovers over it. You could create a directive named HighlightRowDirective
that adds that row highlighting behavior and reuse it throughout your project.
Before you get started writing the tests for directives, you’ll want to know a little more about them.
4.1 What are directives?
- Components
- Structural directives
- Attribute directives
Directives and components are similar. Let’s get started by exploring the differences and similarities between the two.