API reference for Angular Material menu-testing

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

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

Properties
Name Description

static hostSelector: '.mat-menu-trigger'

The selector for the host element of a MatMenu instance.

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

Omit<ItemFilters, "ancestor">

subItemFilters

...subItemFilters

Omit<ItemFilters, "ancestor">[]

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
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
getItems

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

Parameters

filters?

Omit<ItemFilters, "ancestor">

Returns
Promise<Item[]>

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
isFocused

Whether the menu is focused.

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.

static
with

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

Parameters

options

MenuHarnessFilters = {}

Returns
HarnessPredicate<MatMenuHarness>

a HarnessPredicate configured with the given options.

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

Properties
Name Description

static hostSelector: '.mat-menu-item'

The selector for the host element of a MatMenuItem instance.

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
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
getSubmenu

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

Returns
Promise<Menu | 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>

async
isFocused

Whether the menu item is focused.

Returns
Promise<boolean>

static
with

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

Parameters

options

MenuItemHarnessFilters = {}

Returns
HarnessPredicate<MatMenuItemHarness>

a HarnessPredicate configured with the given options.

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.