@@ -846,13 +846,18 @@ describe('MDC-based MatChipGrid', () => {
846846 let errorTestComponent : ChipGridWithFormErrorMessages ;
847847 let containerEl : HTMLElement ;
848848 let chipGridEl : HTMLElement ;
849+ let inputEl : HTMLElement ;
849850
850- beforeEach ( ( ) => {
851+ beforeEach ( fakeAsync ( ( ) => {
851852 fixture = createComponent ( ChipGridWithFormErrorMessages ) ;
853+ flush ( ) ;
854+ fixture . detectChanges ( ) ;
855+
852856 errorTestComponent = fixture . componentInstance ;
853857 containerEl = fixture . debugElement . query ( By . css ( 'mat-form-field' ) ) ! . nativeElement ;
854858 chipGridEl = fixture . debugElement . query ( By . css ( 'mat-chip-grid' ) ) ! . nativeElement ;
855- } ) ;
859+ inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
860+ } ) ) ;
856861
857862 it ( 'should not show any errors if the user has not interacted' , ( ) => {
858863 expect ( errorTestComponent . formControl . untouched )
@@ -901,6 +906,7 @@ describe('MDC-based MatChipGrid', () => {
901906 . toBe ( 0 ) ;
902907
903908 dispatchFakeEvent ( fixture . debugElement . query ( By . css ( 'form' ) ) ! . nativeElement , 'submit' ) ;
909+ flush ( ) ;
904910 fixture . detectChanges ( ) ;
905911
906912 fixture . whenStable ( ) . then ( ( ) => {
@@ -917,10 +923,12 @@ describe('MDC-based MatChipGrid', () => {
917923 . withContext ( 'Expected aria-invalid to be set to "true".' )
918924 . toBe ( 'true' ) ;
919925 } ) ;
926+ flush ( ) ;
920927 } ) ) ;
921928
922929 it ( 'should hide the errors and show the hints once the chip grid becomes valid' , fakeAsync ( ( ) => {
923930 errorTestComponent . formControl . markAsTouched ( ) ;
931+ flush ( ) ;
924932 fixture . detectChanges ( ) ;
925933
926934 fixture . whenStable ( ) . then ( ( ) => {
@@ -935,6 +943,7 @@ describe('MDC-based MatChipGrid', () => {
935943 . toBe ( 0 ) ;
936944
937945 errorTestComponent . formControl . setValue ( 'something' ) ;
946+ flush ( ) ;
938947 fixture . detectChanges ( ) ;
939948
940949 fixture . whenStable ( ) . then ( ( ) => {
@@ -949,6 +958,8 @@ describe('MDC-based MatChipGrid', () => {
949958 . withContext ( 'Expected one hint to be shown once the input is valid.' )
950959 . toBe ( 1 ) ;
951960 } ) ;
961+
962+ flush ( ) ;
952963 } ) ;
953964 } ) ) ;
954965
@@ -959,27 +970,31 @@ describe('MDC-based MatChipGrid', () => {
959970 expect ( containerEl . querySelector ( 'mat-error' ) ! . getAttribute ( 'aria-live' ) ) . toBe ( 'polite' ) ;
960971 } ) ;
961972
962- it ( 'sets the aria-describedby to reference errors when in error state' , ( ) => {
973+ it ( 'sets the aria-describedby on the input to reference errors when in error state' , fakeAsync ( ( ) => {
963974 let hintId = fixture . debugElement
964975 . query ( By . css ( '.mat-mdc-form-field-hint' ) ) !
965976 . nativeElement . getAttribute ( 'id' ) ;
966- let describedBy = chipGridEl . getAttribute ( 'aria-describedby' ) ;
977+ let describedBy = inputEl . getAttribute ( 'aria-describedby' ) ;
967978
968979 expect ( hintId ) . withContext ( 'hint should be shown' ) . toBeTruthy ( ) ;
969980 expect ( describedBy ) . toBe ( hintId ) ;
970981
971982 fixture . componentInstance . formControl . markAsTouched ( ) ;
972983 fixture . detectChanges ( ) ;
973984
985+ // Flush the describedby timer and detect changes caused by it.
986+ flush ( ) ;
987+ fixture . detectChanges ( ) ;
988+
974989 let errorIds = fixture . debugElement
975990 . queryAll ( By . css ( '.mat-mdc-form-field-error' ) )
976991 . map ( el => el . nativeElement . getAttribute ( 'id' ) )
977992 . join ( ' ' ) ;
978- describedBy = chipGridEl . getAttribute ( 'aria-describedby' ) ;
993+ let errorDescribedBy = inputEl . getAttribute ( 'aria-describedby' ) ;
979994
980995 expect ( errorIds ) . withContext ( 'errors should be shown' ) . toBeTruthy ( ) ;
981- expect ( describedBy ) . toBe ( errorIds ) ;
982- } ) ;
996+ expect ( errorDescribedBy ) . toBe ( errorIds ) ;
997+ } ) ) ;
983998 } ) ;
984999
9851000 function createComponent < T > (
0 commit comments