API reference for Angular Material snack-bar-testing

import {MatSnackBarHarness} from '@angular/material/snack-bar/testing';

Harness for interacting with a standard mat-snack-bar in tests.

Properties
Name Description

static hostSelector: '.mat-snack-bar-container'

The selector for the host element of a MatSnackBar instance.

Methods
async
dismissWithAction

Dismisses the snack-bar by clicking the action button. Method cannot be used for snack-bar's without action or with custom content.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getActionDescription

Gets the description of the snack-bar. Method cannot be used for snack-bar's without action or with custom content.

Returns
Promise<string>

async
getAllChildLoaders
Parameters

selector

S

Returns
Promise<HarnessLoader[]>

async
getAllHarnesses
Parameters

query

HarnessQuery<T>

Returns
Promise<T[]>

async
getAriaLive

Gets the aria-live of the snack-bar's live region. The aria-live of a snack-bar is determined based on the ARIA politeness specified in the snack-bar config.

Returns
Promise<AriaLivePoliteness>

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
getMessage

Gets the message of the snack-bar. Method cannot be used for snack-bar's with custom content.

Returns
Promise<string>

async
hasAction

Whether the snack-bar has an action. Method cannot be used for snack-bar's with custom content.

Returns
Promise<boolean>

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
isDismissed

Gets whether the snack-bar has been dismissed.

Returns
Promise<boolean>

static
with

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

Parameters

options

SnackBarHarnessFilters = {}

Options for filtering which snack bar instances are considered a match.

Returns
HarnessPredicate<MatSnackBarHarness>

a HarnessPredicate configured with the given options.

Deprecated
async
getRole

Gets the role of the snack-bar. The role of a snack-bar is determined based on the ARIA politeness specified in the snack-bar config.

Returns
Promise<'alert' | 'status' | null>

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