API reference for Angular Material checkbox-testing

import {MatCheckboxHarness} from '@angular/material/checkbox/testing';

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

Methods
async
blur

Blurs the checkbox.

Returns
Promise<void>

Promise that resolves when the action completes.

async
check

Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing nothing if it is already checked.

Note: This attempts to check the checkbox as a user would, by clicking it. Therefore if you are using MAT_CHECKBOX_CLICK_ACTION to change the behavior on click, calling this method might not have the expected result.

Returns
Promise<void>

Promise that resolves when the action completes.

async
focus

Focuses the checkbox.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getAriaLabel

Gets the checkbox's aria-label.

Returns
Promise<string | null>

async
getAriaLabelledby

Gets the checkbox's aria-labelledby.

Returns
Promise<string | null>

async
getLabelText

Gets the checkbox's label text.

Returns
Promise<string>

async
getName

Gets the checkbox's name.

Returns
Promise<string | null>

async
getValue

Gets the checkbox's value.

Returns
Promise<string | null>

async
host

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

Returns
Promise<TestElement>

async
isChecked

Whether the checkbox is checked.

Returns
Promise<boolean>

async
isDisabled

Whether the checkbox is disabled.

Returns
Promise<boolean>

async
isIndeterminate

Whether the checkbox is in an indeterminate state.

Returns
Promise<boolean>

async
isRequired

Whether the checkbox is required.

Returns
Promise<boolean>

async
isValid

Whether the checkbox is valid.

Returns
Promise<boolean>

async
toggle

Toggles the checked state of the checkbox.

Note: This attempts to toggle the checkbox as a user would, by clicking it. Therefore if you are using MAT_CHECKBOX_CLICK_ACTION to change the behavior on click, calling this method might not have the expected result.

Returns
Promise<void>

Promise that resolves when the action completes.

async
uncheck

Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing nothing if it is already unchecked.

Note: This attempts to uncheck the checkbox as a user would, by clicking it. Therefore if you are using MAT_CHECKBOX_CLICK_ACTION to change the behavior on click, calling this method might not have the expected result.

Returns
Promise<void>

Promise that resolves when the action completes.

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

Properties
Name Description

label: string | RegExp

Only find instances whose label matches the given value.

name: string

Only find instances whose name attribute is the given value.