@@ -11,10 +11,12 @@ describe('MatBadge', () => {
11
11
let badgeDebugElement : DebugElement ;
12
12
13
13
beforeEach ( fakeAsync ( ( ) => {
14
- TestBed . configureTestingModule ( {
15
- imports : [ MatBadgeModule ] ,
16
- declarations : [ BadgeTestApp ] ,
17
- } ) . compileComponents ( ) ;
14
+ TestBed
15
+ . configureTestingModule ( {
16
+ imports : [ MatBadgeModule ] ,
17
+ declarations : [ BadgeTestApp , PreExistingBadge , NestedBadge ] ,
18
+ } )
19
+ . compileComponents ( ) ;
18
20
19
21
fixture = TestBed . createComponent ( BadgeTestApp ) ;
20
22
testComponent = fixture . debugElement . componentInstance ;
@@ -184,6 +186,20 @@ describe('MatBadge', () => {
184
186
expect ( badgeContent . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
185
187
} ) ;
186
188
189
+ it ( 'should clear any pre-existing badges' , ( ) => {
190
+ const preExistingFixture = TestBed . createComponent ( PreExistingBadge ) ;
191
+ preExistingFixture . detectChanges ( ) ;
192
+
193
+ expect ( preExistingFixture . nativeElement . querySelectorAll ( '.mat-badge-content' ) . length ) . toBe ( 1 ) ;
194
+ } ) ;
195
+
196
+ it ( 'should not clear badge content from child elements' , ( ) => {
197
+ const preExistingFixture = TestBed . createComponent ( NestedBadge ) ;
198
+ preExistingFixture . detectChanges ( ) ;
199
+
200
+ expect ( preExistingFixture . nativeElement . querySelectorAll ( '.mat-badge-content' ) . length ) . toBe ( 2 ) ;
201
+ } ) ;
202
+
187
203
} ) ;
188
204
189
205
/** Test component that contains a MatBadge. */
@@ -214,3 +230,27 @@ class BadgeTestApp {
214
230
badgeDescription : string ;
215
231
badgeDisabled = false ;
216
232
}
233
+
234
+
235
+ @Component ( {
236
+ template : `
237
+ <span matBadge="Hello">
238
+ home
239
+ <div class="mat-badge-content">Pre-existing badge</div>
240
+ </span>
241
+ `
242
+ } )
243
+ class PreExistingBadge {
244
+ }
245
+
246
+
247
+ @Component ( {
248
+ template : `
249
+ <span matBadge="Hello">
250
+ home
251
+ <span matBadge="Hi">Something</span>
252
+ </span>
253
+ `
254
+ } )
255
+ class NestedBadge {
256
+ }
0 commit comments