@@ -61,35 +61,39 @@ describe('MdAutocomplete', () => {
6161 input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
6262 } ) ;
6363
64- it ( 'should open the panel when the input is focused' , ( ) => {
64+ it ( 'should open the panel when the input is focused' , async ( ( ) => {
6565 expect ( fixture . componentInstance . trigger . panelOpen )
6666 . toBe ( false , `Expected panel state to start out closed.` ) ;
6767
6868 dispatchFakeEvent ( input , 'focus' ) ;
69- fixture . detectChanges ( ) ;
69+ fixture . whenStable ( ) . then ( ( ) => {
70+ fixture . detectChanges ( ) ;
7071
71- expect ( fixture . componentInstance . trigger . panelOpen )
72- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
73- expect ( overlayContainerElement . textContent )
74- . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
75- expect ( overlayContainerElement . textContent )
76- . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
77- } ) ;
72+ expect ( fixture . componentInstance . trigger . panelOpen )
73+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
74+ expect ( overlayContainerElement . textContent )
75+ . toContain ( 'Alabama' , `Expected panel to display when input is focused.` ) ;
76+ expect ( overlayContainerElement . textContent )
77+ . toContain ( 'California' , `Expected panel to display when input is focused.` ) ;
78+ } ) ;
79+ } ) ) ;
7880
79- it ( 'should open the panel programmatically' , ( ) => {
81+ it ( 'should open the panel programmatically' , async ( ( ) => {
8082 expect ( fixture . componentInstance . trigger . panelOpen )
8183 . toBe ( false , `Expected panel state to start out closed.` ) ;
8284
8385 fixture . componentInstance . trigger . openPanel ( ) ;
84- fixture . detectChanges ( ) ;
86+ fixture . whenStable ( ) . then ( ( ) => {
87+ fixture . detectChanges ( ) ;
8588
86- expect ( fixture . componentInstance . trigger . panelOpen )
87- . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
88- expect ( overlayContainerElement . textContent )
89- . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
90- expect ( overlayContainerElement . textContent )
91- . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
92- } ) ;
89+ expect ( fixture . componentInstance . trigger . panelOpen )
90+ . toBe ( true , `Expected panel state to read open when opened programmatically.` ) ;
91+ expect ( overlayContainerElement . textContent )
92+ . toContain ( 'Alabama' , `Expected panel to display when opened programmatically.` ) ;
93+ expect ( overlayContainerElement . textContent )
94+ . toContain ( 'California' , `Expected panel to display when opened programmatically.` ) ;
95+ } ) ;
96+ } ) ) ;
9397
9498 it ( 'should close the panel when blurred' , async ( ( ) => {
9599 dispatchFakeEvent ( input , 'focus' ) ;
@@ -185,8 +189,6 @@ describe('MdAutocomplete', () => {
185189 fixture . whenStable ( ) . then ( ( ) => {
186190 fixture . detectChanges ( ) ;
187191
188- expect ( fixture . componentInstance . trigger . panelOpen )
189- . toBe ( true , `Expected panel to stay open when options list is empty.` ) ;
190192 expect ( panel . classList )
191193 . toContain ( 'mat-autocomplete-hidden' , `Expected panel to hide itself when empty.` ) ;
192194 } ) ;
@@ -748,20 +750,43 @@ describe('MdAutocomplete', () => {
748750 . toBe ( 'false' , 'Expected aria-expanded to be false while panel is closed.' ) ;
749751
750752 fixture . componentInstance . trigger . openPanel ( ) ;
751- fixture . detectChanges ( ) ;
753+ fixture . whenStable ( ) . then ( ( ) => {
754+ fixture . detectChanges ( ) ;
752755
753- expect ( input . getAttribute ( 'aria-expanded' ) )
754- . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
756+ expect ( input . getAttribute ( 'aria-expanded' ) )
757+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
755758
756- fixture . componentInstance . trigger . closePanel ( ) ;
757- fixture . detectChanges ( ) ;
759+ fixture . componentInstance . trigger . closePanel ( ) ;
760+ fixture . detectChanges ( ) ;
758761
759- fixture . whenStable ( ) . then ( ( ) => {
760- expect ( input . getAttribute ( 'aria-expanded' ) )
761- . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
762+ fixture . whenStable ( ) . then ( ( ) => {
763+ expect ( input . getAttribute ( 'aria-expanded' ) )
764+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel closes again.' ) ;
765+ } ) ;
762766 } ) ;
763767 } ) ) ;
764768
769+ it ( 'should set aria-expanded properly when the panel is hidden' , async ( ( ) => {
770+ fixture . componentInstance . trigger . openPanel ( ) ;
771+
772+ fixture . whenStable ( ) . then ( ( ) => {
773+ fixture . detectChanges ( ) ;
774+ expect ( input . getAttribute ( 'aria-expanded' ) )
775+ . toBe ( 'true' , 'Expected aria-expanded to be true while panel is open.' ) ;
776+
777+ typeInElement ( 'zz' , input ) ;
778+ fixture . whenStable ( ) . then ( ( ) => {
779+ fixture . detectChanges ( ) ;
780+
781+ fixture . whenStable ( ) . then ( ( ) => {
782+ fixture . detectChanges ( ) ;
783+ expect ( input . getAttribute ( 'aria-expanded' ) )
784+ . toBe ( 'false' , 'Expected aria-expanded to be false when panel hides itself.' ) ;
785+ } ) ;
786+ } ) ;
787+ } ) ;
788+ } ) ) ;
789+
765790 it ( 'should set aria-owns based on the attached autocomplete' , ( ) => {
766791 fixture . componentInstance . trigger . openPanel ( ) ;
767792 fixture . detectChanges ( ) ;
@@ -863,21 +888,24 @@ describe('MdAutocomplete', () => {
863888 } ) . not . toThrowError ( ) ;
864889 } ) ;
865890
866- it ( 'should work when input is wrapped in ngIf' , ( ) => {
891+ it ( 'should work when input is wrapped in ngIf' , async ( ( ) => {
867892 const fixture = TestBed . createComponent ( NgIfAutocomplete ) ;
868893 fixture . detectChanges ( ) ;
869894
870895 const input = fixture . debugElement . query ( By . css ( 'input' ) ) . nativeElement ;
871896 dispatchFakeEvent ( input , 'focus' ) ;
872- fixture . detectChanges ( ) ;
873897
874- expect ( fixture . componentInstance . trigger . panelOpen )
875- . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
876- expect ( overlayContainerElement . textContent )
877- . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
878- expect ( overlayContainerElement . textContent )
879- . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
880- } ) ;
898+ fixture . whenStable ( ) . then ( ( ) => {
899+ fixture . detectChanges ( ) ;
900+
901+ expect ( fixture . componentInstance . trigger . panelOpen )
902+ . toBe ( true , `Expected panel state to read open when input is focused.` ) ;
903+ expect ( overlayContainerElement . textContent )
904+ . toContain ( 'One' , `Expected panel to display when input is focused.` ) ;
905+ expect ( overlayContainerElement . textContent )
906+ . toContain ( 'Two' , `Expected panel to display when input is focused.` ) ;
907+ } ) ;
908+ } ) ) ;
881909
882910 } ) ;
883911} ) ;
0 commit comments