@@ -705,6 +705,65 @@ describe('MDC-based MatAutocomplete', () => {
705
705
} ) . not . toThrow ( ) ;
706
706
} ) ;
707
707
708
+ it ( 'should clear the selected option if it no longer matches the input text while typing' , fakeAsync ( ( ) => {
709
+ const fixture = createComponent ( SimpleAutocomplete ) ;
710
+ fixture . detectChanges ( ) ;
711
+ tick ( ) ;
712
+
713
+ fixture . componentInstance . trigger . openPanel ( ) ;
714
+ fixture . detectChanges ( ) ;
715
+ zone . simulateZoneExit ( ) ;
716
+
717
+ // Select an option and reopen the panel.
718
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
719
+ fixture . detectChanges ( ) ;
720
+ tick ( ) ;
721
+ fixture . detectChanges ( ) ;
722
+ fixture . componentInstance . trigger . openPanel ( ) ;
723
+ fixture . detectChanges ( ) ;
724
+ zone . simulateZoneExit ( ) ;
725
+
726
+ expect ( fixture . componentInstance . options . first . selected ) . toBe ( true ) ;
727
+
728
+ const input = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
729
+ input . value = '' ;
730
+ typeInElement ( input , 'Ala' ) ;
731
+ fixture . detectChanges ( ) ;
732
+ tick ( ) ;
733
+
734
+ expect ( fixture . componentInstance . options . first . selected ) . toBe ( false ) ;
735
+ } ) ) ;
736
+
737
+ it ( 'should not clear the selected option if it no longer matches the input text while typing with requireSelection' , fakeAsync ( ( ) => {
738
+ const fixture = createComponent ( SimpleAutocomplete ) ;
739
+ fixture . componentInstance . requireSelection = true ;
740
+ fixture . detectChanges ( ) ;
741
+ tick ( ) ;
742
+
743
+ fixture . componentInstance . trigger . openPanel ( ) ;
744
+ fixture . detectChanges ( ) ;
745
+ zone . simulateZoneExit ( ) ;
746
+
747
+ // Select an option and reopen the panel.
748
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
749
+ fixture . detectChanges ( ) ;
750
+ tick ( ) ;
751
+ fixture . detectChanges ( ) ;
752
+ fixture . componentInstance . trigger . openPanel ( ) ;
753
+ fixture . detectChanges ( ) ;
754
+ zone . simulateZoneExit ( ) ;
755
+
756
+ expect ( fixture . componentInstance . options . first . selected ) . toBe ( true ) ;
757
+
758
+ const input = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
759
+ input . value = '' ;
760
+ typeInElement ( input , 'Ala' ) ;
761
+ fixture . detectChanges ( ) ;
762
+ tick ( ) ;
763
+
764
+ expect ( fixture . componentInstance . options . first . selected ) . toBe ( true ) ;
765
+ } ) ) ;
766
+
708
767
describe ( 'forms integration' , ( ) => {
709
768
let fixture : ComponentFixture < SimpleAutocomplete > ;
710
769
let input : HTMLInputElement ;
0 commit comments