@@ -11,10 +11,12 @@ describe('MatBadge', () => {
1111 let badgeDebugElement : DebugElement ;
1212
1313 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 ( ) ;
1820
1921 fixture = TestBed . createComponent ( BadgeTestApp ) ;
2022 testComponent = fixture . debugElement . componentInstance ;
@@ -184,6 +186,20 @@ describe('MatBadge', () => {
184186 expect ( badgeContent . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
185187 } ) ;
186188
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+
187203} ) ;
188204
189205/** Test component that contains a MatBadge. */
@@ -214,3 +230,27 @@ class BadgeTestApp {
214230 badgeDescription : string ;
215231 badgeDisabled = false ;
216232}
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