@@ -5,6 +5,8 @@ import {Component} from '@angular/core';
55import { ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
66import { MatButtonModule } from '@angular/material/button' ;
77import { MatButtonHarness } from '@angular/material/button/testing/button-harness' ;
8+ import { MatIconModule } from '@angular/material/icon' ;
9+ import { MatIconHarness } from '@angular/material/icon/testing/icon-harness' ;
810
911/** Shared tests to run on both the original and MDC-based buttons. */
1012export function runHarnessTests (
@@ -15,7 +17,7 @@ export function runHarnessTests(
1517
1618 beforeEach ( async ( ) => {
1719 await TestBed . configureTestingModule ( {
18- imports : [ buttonModule , PlatformModule ] ,
20+ imports : [ buttonModule , MatIconModule , PlatformModule ] ,
1921 declarations : [ ButtonHarnessTest ] ,
2022 } ) . compileComponents ( ) ;
2123
@@ -30,7 +32,7 @@ export function runHarnessTests(
3032
3133 it ( 'should load all button harnesses' , async ( ) => {
3234 const buttons = await loader . getAllHarnesses ( buttonHarness ) ;
33- expect ( buttons . length ) . toBe ( 14 ) ;
35+ expect ( buttons . length ) . toBe ( 15 ) ;
3436 } ) ;
3537
3638 it ( 'should load button with exact text' , async ( ) => {
@@ -96,6 +98,17 @@ export function runHarnessTests(
9698
9799 expect ( fixture . componentInstance . clicked ) . toBe ( false ) ;
98100 } ) ;
101+
102+ it ( 'should be able to handle nested harnesses' , async ( ) => {
103+ const homeBtn = await loader . getHarness ( buttonHarness . with ( { selector : '#home-icon' } ) ) ;
104+ const favBtn = await loader . getHarness ( buttonHarness . with ( { selector : '#favorite-icon' } ) ) ;
105+
106+ const homeIcon = await homeBtn . getHarness ( MatIconHarness ) ;
107+ const favIcon = await favBtn . getHarness ( MatIconHarness ) ;
108+
109+ expect ( await homeIcon . getName ( ) ) . toBe ( 'home' ) ;
110+ expect ( await favIcon . getName ( ) ) . toBe ( 'favorite' ) ;
111+ } ) ;
99112}
100113
101114@Component ( {
@@ -110,7 +123,12 @@ export function runHarnessTests(
110123 </button>
111124 <button id="raised" type="button" mat-raised-button>Raised button</button>
112125 <button id="stroked" type="button" mat-stroked-button>Stroked button</button>
113- <button id="icon" type="button" mat-icon-button>Icon button</button>
126+ <button id="home-icon" type="button" mat-icon-button>
127+ <mat-icon>home</mat-icon>
128+ </button>
129+ <button id="favorite-icon" type="button" mat-icon-button>
130+ <mat-icon>favorite</mat-icon>
131+ </button>
114132 <button id="fab" type="button" mat-fab>Fab button</button>
115133 <button id="mini-fab" type="button" mat-mini-fab>Mini Fab button</button>
116134
0 commit comments