@@ -243,16 +243,16 @@ describe('MatBadge', () => {
243
243
badgeHostNativeElement = badgeHostDebugElement . nativeElement ;
244
244
} ) ;
245
245
246
- it ( 'should insert the description inline after the host' , ( ) => {
246
+ it ( 'should insert description as next sibling for host' , ( ) => {
247
247
testComponent . description . set ( 'Extra info' ) ;
248
248
fixture . detectChanges ( ) ;
249
249
250
- const inlineDescription = badgeHostNativeElement . querySelector ( '.cdk-visually-hidden' ) ! ;
250
+ const inlineDescription = badgeHostNativeElement . nextSibling ! ;
251
251
expect ( inlineDescription )
252
252
. withContext ( 'A visually hidden description element should exist' )
253
253
. toBeDefined ( ) ;
254
254
expect ( inlineDescription . textContent )
255
- . withContext ( 'The badge host next sibling should contain its description' )
255
+ . withContext ( 'The badge next sibling should contain its description' )
256
256
. toBe ( 'Extra info' ) ;
257
257
258
258
testComponent . description . set ( 'Different info' ) ;
@@ -263,14 +263,34 @@ describe('MatBadge', () => {
263
263
. toBe ( 'Different info' ) ;
264
264
} ) ;
265
265
266
- it ( 'should not apply aria-describedby for non-interactive hosts ' , ( ) => {
266
+ it ( 'should not apply aria-describedby for non-interactive host ' , ( ) => {
267
267
testComponent . description . set ( 'Extra info' ) ;
268
268
fixture . detectChanges ( ) ;
269
269
270
270
expect ( badgeHostNativeElement . hasAttribute ( 'aria-description' ) )
271
271
. withContext ( 'Non-interactive hosts should not have aria-describedby' )
272
272
. toBeFalse ( ) ;
273
273
} ) ;
274
+
275
+ it ( 'should not insert description as next sibling if description is not provided' , ( ) => {
276
+ fixture . detectChanges ( ) ;
277
+
278
+ expect ( badgeHostNativeElement . nextSibling ) . toBeFalsy ( ) ;
279
+ } ) ;
280
+
281
+ it ( 'should not create multiple description elements if description changes' , ( ) => {
282
+ testComponent . description . set ( 'one' ) ;
283
+ fixture . detectChanges ( ) ;
284
+
285
+ let siblings = fixture . nativeElement . querySelectorAll ( '.cdk-visually-hidden' ) ;
286
+ expect ( siblings . length ) . toBe ( 1 ) ;
287
+
288
+ testComponent . description . set ( 'two' ) ;
289
+ fixture . detectChanges ( ) ;
290
+
291
+ siblings = fixture . nativeElement . querySelectorAll ( '.cdk-visually-hidden' ) ;
292
+ expect ( siblings . length ) . toBe ( 1 ) ;
293
+ } ) ;
274
294
} ) ;
275
295
} ) ;
276
296
0 commit comments