API reference for Angular Material tabs-testing

import {MatTabGroupHarness} from '@angular/material/tabs/testing';

Harness for interacting with a mat-tab-group in tests.

Properties
Name Description

static hostSelector: '.mat-mdc-tab-group'

The selector for the host element of a MatTabGroup instance.

Methods
async
getSelectedTab

Gets the selected tab of the tab group.

Returns
Promise<MatTabHarness>

async
getTabs

Gets the list of tabs in the tab group.

Parameters

filter

TabHarnessFilters = {}

Optionally filters which tabs are included.

Returns
Promise<MatTabHarness[]>

async
host

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

Returns
Promise<TestElement>

async
selectTab

Selects a tab in this tab group.

Parameters

filter

TabHarnessFilters = {}

An optional filter to apply to the child tabs. The first tab matching the filter will be selected.

Returns
Promise<void>

Promise that resolves when the action completes.

static
with

Gets a HarnessPredicate that can be used to search for a tab group with specific attributes.

Parameters

options

TabGroupHarnessFilters = {}

Options for filtering which tab group instances are considered a match.

Returns
HarnessPredicate<T>

a HarnessPredicate configured with the given options.

Harness for interacting with an Angular Material tab in tests.

Properties
Name Description

static hostSelector: '.mat-mdc-tab'

The selector for the host element of a MatTab instance.

Methods
async
countHarnesses

Returns the number of matching harnesses for the given query within the current harness's content.

Parameters

query

HarnessQuery<T>

The harness query to search for.

Returns
Promise<number>

The number of matching harnesses for the given query.

async
getAllChildLoaders

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.

Parameters

selector

S

The selector for elements in the component's content.

Returns
Promise<HarnessLoader[]>

A list of HarnessLoader for each element matching the given selector.

async
getAllHarnesses

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

Parameters

query

HarnessQuery<T>

The harness query to search for.

Returns
Promise<T[]>

The list of harness matching the given query.

async
getAriaLabel

Gets the aria-label of the tab.

Returns
Promise<string | null>

async
getAriaLabelledby

Gets the value of the "aria-labelledby" attribute.

Returns
Promise<string | null>

async
getChildLoader

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

Parameters

selector

S

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

Returns
Promise<HarnessLoader>

A HarnessLoader that searches for harnesses under the given selector.

async
getHarness

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

Parameters

query

HarnessQuery<T>

The harness query to search for.

Returns
Promise<T>

The first harness matching the given query.

async
getHarnessAtIndex

Gets a matching harness for the given query and index within the current harness's content.

Parameters

query

HarnessQuery<T>

The harness query to search for.

index

number

The zero-indexed offset of the component to find.

Returns
Promise<T>

The first harness matching the given query.

async
getHarnessOrNull

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

Parameters

query

HarnessQuery<T>

The harness query to search for.

Returns
Promise<T | null>

The first harness matching the given query, or null if none is found.

async
getLabel

Gets the label of the tab.

Returns
Promise<string>

async
getRootHarnessLoader
Returns
Promise<HarnessLoader>

async
getTextContent

Gets the text content of the tab.

Returns
Promise<string>

async
hasHarness

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

Parameters

query

HarnessQuery<T>

The harness query to search for.

Returns
Promise<boolean>

Whether there is matching harnesses for the given query.

async
host

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

Returns
Promise<TestElement>

async
isDisabled

Whether the tab is disabled.

Returns
Promise<boolean>

async
isSelected

Whether the tab is selected.

Returns
Promise<boolean>

async
select

Selects the given tab by clicking on the label. Tab cannot be selected if disabled.

Returns
Promise<void>

Promise that resolves when the action completes.

static
with

Gets a HarnessPredicate that can be used to search for a tab with specific attributes.

Parameters

options

TabHarnessFilters = {}

Options for filtering which tab instances are considered a match.

Returns
HarnessPredicate<T>

a HarnessPredicate configured with the given options.

Harness for interacting with a mat-tab-nav-bar in tests.

Properties
Name Description

static hostSelector: '.mat-mdc-tab-nav-bar'

The selector for the host element of a MatTabNavBar instance.

Methods
async
clickLink

Clicks a link inside the nav bar.

Parameters

filter

TabLinkHarnessFilters = {}

An optional filter to apply to the child link. The first link matching the filter will be clicked.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getActiveLink

Gets the active link in the nav bar.

Returns
Promise<MatTabLinkHarness>

async
getLinks

Gets the list of links in the nav bar.

Parameters

filter

TabLinkHarnessFilters = {}

Optionally filters which links are included.

Returns
Promise<MatTabLinkHarness[]>

async
getPanel

Gets the panel associated with the nav bar.

Returns
Promise<MatTabNavPanelHarness>

async
host

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

Returns
Promise<TestElement>

static
with

Gets a HarnessPredicate that can be used to search for a tab nav bar with specific attributes.

Parameters

options

TabNavBarHarnessFilters = {}

Options for filtering which tab nav bar instances are considered a match.

Returns
HarnessPredicate<T>

a HarnessPredicate configured with the given options.

Harness for interacting with a Angular Material tab link in tests.

Properties
Name Description

static hostSelector: '.mat-mdc-tab-link'

The selector for the host element of a MatTabLink instance.

Methods
async
click

Clicks on the link.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getLabel

Gets the label of the link.

Returns
Promise<string>

async
host

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

Returns
Promise<TestElement>

async
isActive

Whether the link is active.

Returns
Promise<boolean>

async
isDisabled

Whether the link is disabled.

Returns
Promise<boolean>

static
with

Gets a HarnessPredicate that can be used to search for a tab link with specific attributes.

Parameters

options

TabLinkHarnessFilters = {}

Options for filtering which tab link instances are considered a match.

Returns
HarnessPredicate<T>

a HarnessPredicate configured with the given options.

A set of criteria that can be used to filter a list of MatTabHarness instances.

Properties
Name Description

label: string | RegExp

Only find instances whose label matches the given value.

selected: boolean

Only find instances whose selected state matches the given value.

A set of criteria that can be used to filter a list of MatTabGroupHarness instances.

Properties
Name Description

selectedTabLabel: string | RegExp

Only find instances whose selected tab label matches the given value.

A set of criteria that can be used to filter a list of MatTabLinkHarness instances.

Properties
Name Description

label: string | RegExp

Only find instances whose label matches the given value.

A set of criteria that can be used to filter a list of MatTabNavBarHarness instances.

A set of criteria that can be used to filter a list of MatTabNavPanelHarness instances.