@@ -853,13 +853,18 @@ describe('MDC-based MatChipGrid', () => {
853853 let errorTestComponent : ChipGridWithFormErrorMessages ;
854854 let containerEl : HTMLElement ;
855855 let chipGridEl : HTMLElement ;
856+ let inputEl : HTMLElement ;
856857
857- beforeEach ( ( ) => {
858+ beforeEach ( fakeAsync ( ( ) => {
858859 fixture = createComponent ( ChipGridWithFormErrorMessages ) ;
860+ flush ( ) ;
861+ fixture . detectChanges ( ) ;
862+
859863 errorTestComponent = fixture . componentInstance ;
860864 containerEl = fixture . debugElement . query ( By . css ( 'mat-form-field' ) ) ! . nativeElement ;
861865 chipGridEl = fixture . debugElement . query ( By . css ( 'mat-chip-grid' ) ) ! . nativeElement ;
862- } ) ;
866+ inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
867+ } ) ) ;
863868
864869 it ( 'should not show any errors if the user has not interacted' , ( ) => {
865870 expect ( errorTestComponent . formControl . untouched )
@@ -908,6 +913,7 @@ describe('MDC-based MatChipGrid', () => {
908913 . toBe ( 0 ) ;
909914
910915 dispatchFakeEvent ( fixture . debugElement . query ( By . css ( 'form' ) ) ! . nativeElement , 'submit' ) ;
916+ flush ( ) ;
911917 fixture . detectChanges ( ) ;
912918
913919 fixture . whenStable ( ) . then ( ( ) => {
@@ -924,10 +930,12 @@ describe('MDC-based MatChipGrid', () => {
924930 . withContext ( 'Expected aria-invalid to be set to "true".' )
925931 . toBe ( 'true' ) ;
926932 } ) ;
933+ flush ( ) ;
927934 } ) ) ;
928935
929936 it ( 'should hide the errors and show the hints once the chip grid becomes valid' , fakeAsync ( ( ) => {
930937 errorTestComponent . formControl . markAsTouched ( ) ;
938+ flush ( ) ;
931939 fixture . detectChanges ( ) ;
932940
933941 fixture . whenStable ( ) . then ( ( ) => {
@@ -942,6 +950,7 @@ describe('MDC-based MatChipGrid', () => {
942950 . toBe ( 0 ) ;
943951
944952 errorTestComponent . formControl . setValue ( 'something' ) ;
953+ flush ( ) ;
945954 fixture . detectChanges ( ) ;
946955
947956 fixture . whenStable ( ) . then ( ( ) => {
@@ -956,6 +965,8 @@ describe('MDC-based MatChipGrid', () => {
956965 . withContext ( 'Expected one hint to be shown once the input is valid.' )
957966 . toBe ( 1 ) ;
958967 } ) ;
968+
969+ flush ( ) ;
959970 } ) ;
960971 } ) ) ;
961972
@@ -966,27 +977,31 @@ describe('MDC-based MatChipGrid', () => {
966977 expect ( containerEl . querySelector ( 'mat-error' ) ! . getAttribute ( 'aria-live' ) ) . toBe ( 'polite' ) ;
967978 } ) ;
968979
969- it ( 'sets the aria-describedby to reference errors when in error state' , ( ) => {
980+ it ( 'sets the aria-describedby on the input to reference errors when in error state' , fakeAsync ( ( ) => {
970981 let hintId = fixture . debugElement
971982 . query ( By . css ( '.mat-mdc-form-field-hint' ) ) !
972983 . nativeElement . getAttribute ( 'id' ) ;
973- let describedBy = chipGridEl . getAttribute ( 'aria-describedby' ) ;
984+ let describedBy = inputEl . getAttribute ( 'aria-describedby' ) ;
974985
975986 expect ( hintId ) . withContext ( 'hint should be shown' ) . toBeTruthy ( ) ;
976987 expect ( describedBy ) . toBe ( hintId ) ;
977988
978989 fixture . componentInstance . formControl . markAsTouched ( ) ;
979990 fixture . detectChanges ( ) ;
980991
992+ // Flush the describedby timer and detect changes caused by it.
993+ flush ( ) ;
994+ fixture . detectChanges ( ) ;
995+
981996 let errorIds = fixture . debugElement
982997 . queryAll ( By . css ( '.mat-mdc-form-field-error' ) )
983998 . map ( el => el . nativeElement . getAttribute ( 'id' ) )
984999 . join ( ' ' ) ;
985- describedBy = chipGridEl . getAttribute ( 'aria-describedby' ) ;
1000+ let errorDescribedBy = inputEl . getAttribute ( 'aria-describedby' ) ;
9861001
9871002 expect ( errorIds ) . withContext ( 'errors should be shown' ) . toBeTruthy ( ) ;
988- expect ( describedBy ) . toBe ( errorIds ) ;
989- } ) ;
1003+ expect ( errorDescribedBy ) . toBe ( errorIds ) ;
1004+ } ) ) ;
9901005 } ) ;
9911006
9921007 function createComponent < T > (
0 commit comments