angular/components · error
Item matching ${JSON.stringify(itemFilter)} does not have a
Error message
Item matching ${JSON.stringify(itemFilter)} does not have a submenu What it means
`clickItemImplementation` throws when the caller requested a nested click (subItemFilters provided) but the matched menu item has no submenu. `getSubmenu()` returned null, so descending into sub-items is impossible.
Source
Thrown at src/material/menu/testing/menu-harness.ts:230
}
}
export async function clickItemImplementation(
items: MatMenuItemHarness[],
itemFilter: Omit<MenuItemHarnessFilters, 'ancestor'>,
subItemFilters: Omit<MenuItemHarnessFilters, 'ancestor'>[],
): Promise<void> {
if (!items.length) {
throw Error(`Could not find item matching ${JSON.stringify(itemFilter)}`);
}
if (!subItemFilters.length) {
return await items[0].click();
}
const menu = await items[0].getSubmenu();
if (!menu) {
throw Error(`Item matching ${JSON.stringify(itemFilter)} does not have a submenu`);
}
return menu.clickItem(...(subItemFilters as [Omit<MenuItemHarnessFilters, 'ancestor'>]));
}
View on GitHub (pinned to 0411926e7d)
Solutions
- Remove the subItemFilters argument if the item is actually a leaf item
- Verify the template attaches a nested menu (`<ng-template matMenuContent>` or nested `<mat-menu>`) to that item
- Check the item text filter matches the item that truly has the submenu
Example fix
// before
await menuHarness.clickItem({text: 'Close'}, [{text: 'Now'}]);
// after
await menuHarness.clickItem({text: 'Close'}); Defensive patterns
Strategy: validation
Validate before calling
const item = (await menuHarness.getItems({text: 'File'}))[0];
if (!item || !(await item.getSubmenu())) {
throw new Error('Item has no submenu; do not pass subItemFilters');
} Try / catch
try {
await menuHarness.clickItem({text: 'File'}, [{text: 'Open'}]);
} catch (e) {
if (String(e?.message).includes('does not have a submenu')) {
fail(`'File' is a leaf item or submenu is not attached`);
}
throw e;
} Prevention
- Only pass subItemFilters for items with nested menus
- Keep template submenu structure in sync with tests
- Hover parent items so lazy submenu content is attached before asserting
When it happens
Trigger: `await menuHarness.clickItem({text: 'File'}, [{text: 'Open'}])` where the 'File' item was rendered without a `mat-menu` child (no `matMenuContent`/nested menu attached).
Common situations: A submenu was removed or renamed in the template but the test still navigates into it; the item is a leaf action (e.g. 'Close') mistakenly treated as a parent; lazy submenu content not rendered because the parent was not hovered.
Related errors
- Could not find item matching ${JSON.stringify(itemFilter)}
- Could not find first page button inside paginator. Make sure
- Could not find last page button inside paginator. Make sure
- Cannot find page size selector in paginator. Make sure that
- Radio buttons in radio-group have mismatching names.
AI-assisted analysis of angular/components@0411926e7d (2026-08-31).
Data as JSON: /api/errors/fd5dac2a2037d5cd.
Report an issue: GitHub.