API reference for Angular Material menu-testing

import {MatMenuHarness} from '@angular/material/menu/testing';

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

Methods
async
blur

Blurs the menu.

Returns
Promise<void>

Promise that resolves when the action completes.

async
clickItem

Clicks an item in the menu, and optionally continues clicking items in subsequent sub-menus.

Parameters

itemFilter

Pick<MenuItemHarnessFilters, "text" | "selector" | "hasSubmenu">

A filter used to represent which item in the menu should be clicked. The first matching menu item will be clicked.

subItemFilters

A list of filters representing the items to click in any subsequent sub-menus. The first item in the sub-menu matching the corresponding filter in subItemFilters will be clicked.

...subItemFilters

Pick<MenuItemHarnessFilters, "text" | "selector" | "hasSubmenu">[]

Returns
Promise<void>

Promise that resolves when the action completes.

async
close

Closes the menu.

Returns
Promise<void>

Promise that resolves when the action completes.

async
focus

Focuses the menu.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getItems

Gets a list of MatMenuItemHarness representing the items in the menu.

Parameters

filters

Pick<MenuItemHarnessFilters, "text" | "selector" | "hasSubmenu"> = {}

Optionally filters which menu items are included.

Returns
Promise<MatMenuItemHarness[]>

async
getTriggerText

Gets the text of the menu's trigger element.

Returns
Promise<string>

async
host

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

Returns
Promise<TestElement>

async
isDisabled

Whether the menu is disabled.

Returns
Promise<boolean>

async
isOpen

Whether the menu is open.

Returns
Promise<boolean>

async
open

Opens the menu.

Returns
Promise<void>

Promise that resolves when the action completes.

Harness for interacting with a standard mat-menu-item in tests.

Methods
async
blur

Blurs the menu item.

Returns
Promise<void>

Promise that resolves when the action completes.

async
click

Clicks the menu item.

Returns
Promise<void>

Promise that resolves when the action completes.

async
focus

Focuses the menu item.

Returns
Promise<void>

Promise that resolves when the action completes.

async
getSubmenu

Gets the submenu associated with this menu item, or null if none.

Returns
Promise<MatMenuHarness | null>

async
getText

Gets the text of the menu item.

Returns
Promise<string>

async
hasSubmenu

Whether this item has a submenu.

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 menu is disabled.

Returns
Promise<boolean>

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

Properties
Name Description

triggerText: string | RegExp

Only find instances whose trigger text matches the given value.

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

Properties
Name Description

hasSubmenu: boolean

Only find instances that have a sub-menu.

text: string | RegExp

Only find instances whose text matches the given value.