diff --git a/src/cdk/testing/testing.md b/src/cdk/testing/testing.md index bde9d78f4fec..d84d944c3a88 100644 --- a/src/cdk/testing/testing.md +++ b/src/cdk/testing/testing.md @@ -36,15 +36,15 @@ Test authors are developers using component harnesses written by someone else to application. For example, this could be an app developer who uses a third-party menu component and needs to interact with the menu in a unit test. -#### `ComponentHarness` +#### Working with `ComponentHarness` classes -This is the abstract base class for all component harnesses. Every harness extends -`ComponentHarness`. All `ComponentHarness` subclasses have a static property, `hostSelector`, that +`ComponentHarness` is the abstract base class for all component harnesses. Every harness extends +this class. All `ComponentHarness` subclasses have a static property, `hostSelector`, that matches the harness class to instances of the component in the DOM. Beyond that, the API of any given harness is specific to its corresponding component; refer to the component's documentation to learn how to use a specific harness. -#### `TestbedHarnessEnvironment` and `ProtractorHarnessEnvironment` +#### Using `TestbedHarnessEnvironment` and `ProtractorHarnessEnvironment` These classes correspond to different implementations of the component harness system with bindings for specific test environments. Any given test must only import _one_ of these classes. Karma-based @@ -117,7 +117,7 @@ Since Protractor does not deal with fixtures, the API in this environment is sim `HarnessLoader` returned by the `loader()` method should be sufficient for loading all necessary `ComponentHarness` instances. -#### `HarnessLoader` +#### Creating harnesses with `HarnessLoader` Instances of this class correspond to a specific DOM element (the "root element" of the loader) and are used to create `ComponentHarness` instances for elements under this root element. @@ -134,8 +134,8 @@ are used to create `ComponentHarness` instances for elements under this root ele Calls to `getHarness` and `getAllHarnesses` can either take `ComponentHarness` subclass or a `HarnessPredicate`. `HarnessPredicate` applies additional restrictions to the search (e.g. searching for a button that has some particular text, etc). The -[details of `HarnessPredicate`](#harnesspredicate) are discussed in the -[API for component harness authors](#api-for-component-harness-authors); harness authors should +[details of `HarnessPredicate`](#filtering-harness-instances-with-harnesspredicate) are discussed in +the [API for component harness authors](#api-for-component-harness-authors); harness authors should provide convenience methods on their `ComponentHarness` subclass to facilitate creation of `HarnessPredicate` instances. However, if the harness author's API is not sufficient, they can be created manually. @@ -169,11 +169,378 @@ it('reads properties in parallel', async () => { ### API for component harness authors -TODO(mmalerba): Fill in docs for harness authors +Component harness authors are developers who maintain some reusable Angular component, and want to +create a test harness for it, that users of the component can use in their tests. For example, this +could be an author of a third party Angular component library or a developer who maintains a set of +common components for a large Angular application. -#### `HarnessPredicate` +#### Extending `ComponentHarness` -TODO(mmalerba): Fill in docs for `HarnessPredicate` +The abstract `ComponentHarness` class is the base class for all component harnesses. To create a +custom component harness, extend `ComponentHarness` and implement the static property +`hostSelector`. The `hostSelector` property identifies elements in the DOM that match this harness +subclass. In most cases the `hostSelector` should be the same as the `selector` of the corresponding +`Component` or `Directive`. For example, consider a simple popup component: + +```ts +@Component({ + selector: 'my-popup', + template: ` + +