• Overview
@angular/cdk/testing

ContentContainerComponentHarness

Class

Base class for component harnesses that authors should extend if they anticipate that consumers of the harness may want to access other harnesses within the <ng-content> of the component.

API

  
    abstract class ContentContainerComponentHarness<S extends string = string> extends ComponentHarness implements HarnessLoader {}
  
  

getChildLoader

Promise<HarnessLoader>

Gets a HarnessLoader that searches for harnesses under the first element matching the given selector within the current harness's content.

@paramselectorS

The selector for an element in the component's content.

@returnsPromise<HarnessLoader>

getAllChildLoaders

Promise<HarnessLoader[]>

Gets a list of HarnessLoader for each element matching the given selector under the current harness's cotnent that searches for harnesses under that element.

@paramselectorS

The selector for elements in the component's content.

@returnsPromise<HarnessLoader[]>

getHarness

Promise<T>

Gets the first matching harness for the given query within the current harness's content.

@paramqueryHarnessQuery<T>

The harness query to search for.

@returnsPromise<T>

getHarnessOrNull

Promise<T | null>

Gets the first matching harness for the given query within the current harness's content.

@paramqueryHarnessQuery<T>

The harness query to search for.

@returnsPromise<T | null>

getAllHarnesses

Promise<T[]>

Gets all matching harnesses for the given query within the current harness's content.

@paramqueryHarnessQuery<T>

The harness query to search for.

@returnsPromise<T[]>

hasHarness

Promise<boolean>

Checks whether there is a matching harnesses for the given query within the current harness's content.

@paramqueryHarnessQuery<T>

The harness query to search for.

@returnsPromise<boolean>

getRootHarnessLoader

Promise<HarnessLoader>

Gets the root harness loader from which to start searching for content contained by this harness.

@returnsPromise<HarnessLoader>

host

Promise<TestElement>

Gets a Promise for the TestElement representing the host element of the component.

@returnsPromise<TestElement>

documentRootLocatorFactory

LocatorFactory

Gets a LocatorFactory for the document root element. This factory can be used to create locators for elements that a component creates outside of its own root element. (e.g. by appending to document.body).

locatorFor

() => Promise<LocatorFnResult<T>>

Creates an asynchronous locator function that can be used to find a ComponentHarness instance or element under the host element of this ComponentHarness.

For example, given the following DOM and assuming DivHarness.hostSelector is 'div'

          
<div id="d1"></div><div id="d2"></div>

then we expect:

          
await ch.locatorFor(DivHarness, 'div')() // Gets a `DivHarness` instance for #d1await ch.locatorFor('div', DivHarness)() // Gets a `TestElement` instance for #d1await ch.locatorFor('span')()            // Throws because the `Promise` rejects
@paramqueriesT

A list of queries specifying which harnesses and elements to search for:

@returns() => Promise<LocatorFnResult<T>>

locatorForOptional

() => Promise<LocatorFnResult<T> | null>

Creates an asynchronous locator function that can be used to find a ComponentHarness instance or element under the host element of this ComponentHarness.

For example, given the following DOM and assuming DivHarness.hostSelector is 'div'

          
<div id="d1"></div><div id="d2"></div>

then we expect:

          
await ch.locatorForOptional(DivHarness, 'div')() // Gets a `DivHarness` instance for #d1await ch.locatorForOptional('div', DivHarness)() // Gets a `TestElement` instance for #d1await ch.locatorForOptional('span')()            // Gets `null`
@paramqueriesT

A list of queries specifying which harnesses and elements to search for:

@returns() => Promise<LocatorFnResult<T> | null>

locatorForAll

() => Promise<LocatorFnResult<T>[]>

Creates an asynchronous locator function that can be used to find ComponentHarness instances or elements under the host element of this ComponentHarness.

For example, given the following DOM and assuming DivHarness.hostSelector is 'div' and IdIsD1Harness.hostSelector is '#d1'

          
<div id="d1"></div><div id="d2"></div>

then we expect:

          
// Gets [DivHarness for #d1, TestElement for #d1, DivHarness for #d2, TestElement for #d2]await ch.locatorForAll(DivHarness, 'div')()// Gets [TestElement for #d1, TestElement for #d2]await ch.locatorForAll('div', '#d1')()// Gets [DivHarness for #d1, IdIsD1Harness for #d1, DivHarness for #d2]await ch.locatorForAll(DivHarness, IdIsD1Harness)()// Gets []await ch.locatorForAll('span')()
@paramqueriesT

A list of queries specifying which harnesses and elements to search for:

@returns() => Promise<LocatorFnResult<T>[]>

forceStabilize

Promise<void>

Flushes change detection and async tasks in the Angular zone. In most cases it should not be necessary to call this manually. However, there may be some edge cases where it is needed to fully flush animation events.

@returnsPromise<void>

waitForTasksOutsideAngular

Promise<void>

Waits for all scheduled or running async tasks to complete. This allows harness authors to wait for async tasks outside of the Angular zone.

@returnsPromise<void>
Jump to details