@@ -5,6 +5,8 @@ import {Component} from '@angular/core';
5
5
import { ComponentFixture , inject , TestBed } from '@angular/core/testing' ;
6
6
import { MatButtonModule } from '@angular/material/button' ;
7
7
import { 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' ;
8
10
9
11
/** Shared tests to run on both the original and MDC-based buttons. */
10
12
export function runHarnessTests (
@@ -15,7 +17,7 @@ export function runHarnessTests(
15
17
16
18
beforeEach ( async ( ) => {
17
19
await TestBed . configureTestingModule ( {
18
- imports : [ buttonModule , PlatformModule ] ,
20
+ imports : [ buttonModule , MatIconModule , PlatformModule ] ,
19
21
declarations : [ ButtonHarnessTest ] ,
20
22
} ) . compileComponents ( ) ;
21
23
@@ -30,7 +32,7 @@ export function runHarnessTests(
30
32
31
33
it ( 'should load all button harnesses' , async ( ) => {
32
34
const buttons = await loader . getAllHarnesses ( buttonHarness ) ;
33
- expect ( buttons . length ) . toBe ( 14 ) ;
35
+ expect ( buttons . length ) . toBe ( 15 ) ;
34
36
} ) ;
35
37
36
38
it ( 'should load button with exact text' , async ( ) => {
@@ -96,6 +98,17 @@ export function runHarnessTests(
96
98
97
99
expect ( fixture . componentInstance . clicked ) . toBe ( false ) ;
98
100
} ) ;
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
+ } ) ;
99
112
}
100
113
101
114
@Component ( {
@@ -110,7 +123,12 @@ export function runHarnessTests(
110
123
</button>
111
124
<button id="raised" type="button" mat-raised-button>Raised button</button>
112
125
<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>
114
132
<button id="fab" type="button" mat-fab>Fab button</button>
115
133
<button id="mini-fab" type="button" mat-mini-fab>Mini Fab button</button>
116
134
0 commit comments