API reference for Angular Material button-testing

import {MatButtonHarness} from '@angular/material/button/testing';

Harness for interacting with a standard mat-button in tests.

Properties
Name Description

static hostSelector: `[mat-button], [mat-raised-button], [mat-flat-button], [mat-icon-button], [mat-stroked-button], [mat-fab], [mat-mini-fab]`

The selector for the host element of a MatButton instance.

Methods
async
blur

Blurs the button.

Returns
Promise<void>

Promise that resolves when the action completes.

async
click

Clicks the button at the given position relative to its top-left.

Parameters

relativeX

number

The relative x position of the click.

relativeY

number

The relative y position of the click.

Returns
Promise<void>

Promise that resolves when the action completes.

async
click

Clicks the button at its center.

Parameters

location

"center"

Returns
Promise<void>

Promise that resolves when the action completes.

async
click

Clicks the button.

Returns
Promise<void>

Promise that resolves when the action completes.

async
focus

Focuses the button.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getAllChildLoaders
Parameters

selector

S

Returns
Promise<HarnessLoader[]>

async
getAllHarnesses
Parameters

query

HarnessQuery<T>

Returns
Promise<T[]>

async
getChildLoader
Parameters

selector

S

Returns
Promise<HarnessLoader>

async
getHarness
Parameters

query

HarnessQuery<T>

Returns
Promise<T>

async
getHarnessOrNull
Parameters

query

HarnessQuery<T>

Returns
Promise<T | null>

async
getText

Gets the button's label text.

Returns
Promise<string>

async
hasHarness
Parameters

query

HarnessQuery<T>

Returns
Promise<boolean>

async
host

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

Returns
Promise<TestElement>

async
isDisabled

Whether the button is disabled.

Returns
Promise<boolean>

async
isFocused

Whether the button is focused.

Returns
Promise<boolean>

static
with

Gets a HarnessPredicate that can be used to search for a MatButtonHarness that meets certain criteria.

Parameters

options

ButtonHarnessFilters = {}

Options for filtering which button instances are considered a match.

Returns
HarnessPredicate<MatButtonHarness>

a HarnessPredicate configured with the given options.

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

Properties
Name Description

text: string | RegExp

Only find instances whose text matches the given value.