@@ -66,35 +66,39 @@ describe('MdAutocomplete', () => {
6666 input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
6767 } ) ;
6868
69- it ( 'should open the panel when the input is focused' , ( ) => {
69+ it ( 'should open the panel when the input is focused' , async ( ( ) => {
7070 expect ( fixture . componentInstance . trigger . panelOpen )
7171 . toBe ( false , `Expected panel state to start out closed.` ) ;
7272
7373 dispatchFakeEvent ( input , 'focus' ) ;
74- fixture . detectChanges ( ) ;
74+ fixture . whenStable ( ) . then ( ( ) => {
75+ fixture . detectChanges ( ) ;
7576
76- expect ( fixture . componentInstance . trigger . panelOpen )
77- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
78- expect ( overlayContainerElement . textContent )
79- . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
80- expect ( overlayContainerElement . textContent )
81- . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
82- } ) ;
77+ expect ( fixture . componentInstance . trigger . panelOpen )
78+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
79+ expect ( overlayContainerElement . textContent )
80+ . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
81+ expect ( overlayContainerElement . textContent )
82+ . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
83+ } ) ;
84+ } ) ) ;
8385
84- it ( 'should open the panel programmatically' , ( ) => {
86+ it ( 'should open the panel programmatically' , async ( ( ) => {
8587 expect ( fixture . componentInstance . trigger . panelOpen )
8688 . toBe ( false , `Expected panel state to start out closed.` ) ;
8789
8890 fixture . componentInstance . trigger . openPanel ( ) ;
89- fixture . detectChanges ( ) ;
91+ fixture . whenStable ( ) . then ( ( ) => {
92+ fixture . detectChanges ( ) ;
9093
91- expect ( fixture . componentInstance . trigger . panelOpen )
92- . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
93- expect ( overlayContainerElement . textContent )
94- . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
95- expect ( overlayContainerElement . textContent )
96- . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
97- } ) ;
94+ expect ( fixture . componentInstance . trigger . panelOpen )
95+ . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
96+ expect ( overlayContainerElement . textContent )
97+ . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
98+ expect ( overlayContainerElement . textContent )
99+ . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
100+ } ) ;
101+ } ) ) ;
98102
99103 it ( 'should close the panel when blurred' , async ( ( ) => {
100104 dispatchFakeEvent ( input , 'focus' ) ;
@@ -190,8 +194,6 @@ describe('MdAutocomplete', () => {
190194 fixture . whenStable ( ) . then ( ( ) => {
191195 fixture . detectChanges ( ) ;
192196
193- expect ( fixture . componentInstance . trigger . panelOpen )
194- . toBe ( true , `Expected panel to stay open when options list is empty.` ) ;
195197 expect ( panel . classList )
196198 . toContain ( 'mat-autocomplete-hidden' , `Expected panel to hide itself when empty.` ) ;
197199 } ) ;
@@ -774,20 +776,43 @@ describe('MdAutocomplete', () => {
774776 . toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
775777
776778 fixture . componentInstance . trigger . openPanel ( ) ;
777- fixture . detectChanges ( ) ;
779+ fixture . whenStable ( ) . then ( ( ) => {
780+ fixture . detectChanges ( ) ;
778781
779- expect ( input . getAttribute ( 'aria-expanded' ) )
780- . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
782+ expect ( input . getAttribute ( 'aria-expanded' ) )
783+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
781784
782- fixture . componentInstance . trigger . closePanel ( ) ;
783- fixture . detectChanges ( ) ;
785+ fixture . componentInstance . trigger . closePanel ( ) ;
786+ fixture . detectChanges ( ) ;
784787
785- fixture . whenStable ( ) . then ( ( ) => {
786- expect ( input . getAttribute ( 'aria-expanded' ) )
787- . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
788+ fixture . whenStable ( ) . then ( ( ) => {
789+ expect ( input . getAttribute ( 'aria-expanded' ) )
790+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
791+ } ) ;
788792 } ) ;
789793 } ) ) ;
790794
795+ it ( 'should set aria-expanded properly when the panel is hidden' , async ( ( ) => {
796+ fixture . componentInstance . trigger . openPanel ( ) ;
797+
798+ fixture . whenStable ( ) . then ( ( ) => {
799+ fixture . detectChanges ( ) ;
800+ expect ( input . getAttribute ( 'aria-expanded' ) )
801+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
802+
803+ typeInElement ( 'zz' , input ) ;
804+ fixture . whenStable ( ) . then ( ( ) => {
805+ fixture . detectChanges ( ) ;
806+
807+ fixture . whenStable ( ) . then ( ( ) => {
808+ fixture . detectChanges ( ) ;
809+ expect ( input . getAttribute ( 'aria-expanded' ) )
810+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel hides itself.' ) ;
811+ } ) ;
812+ } ) ;
813+ } ) ;
814+ } ) ) ;
815+
791816 it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
792817 fixture . componentInstance . trigger . openPanel ( ) ;
793818 fixture . detectChanges ( ) ;
@@ -901,21 +926,24 @@ describe('MdAutocomplete', () => {
901926 } ) ;
902927 } ) ) ;
903928
904- it ( 'should work when input is wrapped in ngIf' , ( ) => {
929+ it ( 'should work when input is wrapped in ngIf' , async ( ( ) => {
905930 const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
906931 fixture . detectChanges ( ) ;
907932
908933 const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
909934 dispatchFakeEvent ( input , 'focus' ) ;
910- fixture . detectChanges ( ) ;
911935
912- expect ( fixture . componentInstance . trigger . panelOpen )
913- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
914- expect ( overlayContainerElement . textContent )
915- . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
916- expect ( overlayContainerElement . textContent )
917- . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
918- } ) ;
936+ fixture . whenStable ( ) . then ( ( ) => {
937+ fixture . detectChanges ( ) ;
938+
939+ expect ( fixture . componentInstance . trigger . panelOpen )
940+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
941+ expect ( overlayContainerElement . textContent )
942+ . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
943+ expect ( overlayContainerElement . textContent )
944+ . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
945+ } ) ;
946+ } ) ) ;
919947
920948 it ( 'should filter properly with ngIf after setting the active item' , fakeAsync ( ( ) => {
921949 const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
0 commit comments