diff --git a/src/material/list/testing/list-item-harness-base.ts b/src/material/list/testing/list-item-harness-base.ts index d048a3572daa..d535b4c5575a 100644 --- a/src/material/list/testing/list-item-harness-base.ts +++ b/src/material/list/testing/list-item-harness-base.ts @@ -15,6 +15,9 @@ import { } from '@angular/cdk/testing'; import {BaseListItemHarnessFilters, SubheaderHarnessFilters} from './list-harness-filters'; +const iconSelector = '.mat-list-icon'; +const avatarSelector = '.mat-list-avatar'; + /** * Gets a `HarnessPredicate` that applies the given `BaseListItemHarnessFilters` to the given * list item harness. @@ -58,12 +61,12 @@ export const enum MatListItemSection { */ export class MatListItemHarnessBase extends ContentContainerComponentHarness { private _lines = this.locatorForAll('.mat-line'); - private _avatar = this.locatorForOptional('.mat-list-avatar'); - private _icon = this.locatorForOptional('.mat-list-icon'); + private _avatar = this.locatorForOptional(avatarSelector); + private _icon = this.locatorForOptional(iconSelector); /** Gets the full text content of the list item (including text from any font icons). */ async getText(): Promise { - return (await this.host()).text(); + return (await this.host()).text({exclude: `${iconSelector}, ${avatarSelector}`}); } /** Gets the lines of text (`mat-line` elements) in this nav list item. */ diff --git a/src/material/list/testing/shared.spec.ts b/src/material/list/testing/shared.spec.ts index bcb3f6ca840c..7f54d0e45963 100644 --- a/src/material/list/testing/shared.spec.ts +++ b/src/material/list/testing/shared.spec.ts @@ -395,8 +395,8 @@ export function runHarnessTests(
Item
1
- - +
icon
+
Avatar
Section 1
@@ -419,8 +419,8 @@ class ListHarnessTest {}
Item
1
- - +
icon
+
Avatar
Section 1
@@ -445,8 +445,8 @@ class ActionListHarnessTest {
Item
1
- - +
icon
+
Avatar
Section 1
@@ -476,8 +476,8 @@ class NavListHarnessTest {
Item
1
- - +
icon
+
Avatar
Section 1