@@ -848,7 +848,7 @@ describe('MatSelect', () => {
848
848
describe ( 'for options' , ( ) => {
849
849
let fixture : ComponentFixture < BasicSelect > ;
850
850
let trigger : HTMLElement ;
851
- let options : NodeListOf < HTMLElement > ;
851
+ let options : Array < HTMLElement > ;
852
852
853
853
beforeEach ( fakeAsync ( ( ) => {
854
854
fixture = TestBed . createComponent ( BasicSelect ) ;
@@ -857,8 +857,7 @@ describe('MatSelect', () => {
857
857
trigger . click ( ) ;
858
858
fixture . detectChanges ( ) ;
859
859
860
- options =
861
- overlayContainerElement . querySelectorAll ( 'mat-option' ) as NodeListOf < HTMLElement > ;
860
+ options = Array . from ( overlayContainerElement . querySelectorAll ( 'mat-option' ) ) ;
862
861
} ) ) ;
863
862
864
863
it ( 'should set the role of mat-option to option' , fakeAsync ( ( ) => {
@@ -867,10 +866,9 @@ describe('MatSelect', () => {
867
866
expect ( options [ 2 ] . getAttribute ( 'role' ) ) . toEqual ( 'option' ) ;
868
867
} ) ) ;
869
868
870
- it ( 'should set aria-selected on each option' , fakeAsync ( ( ) => {
871
- expect ( options [ 0 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'false' ) ;
872
- expect ( options [ 1 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'false' ) ;
873
- expect ( options [ 2 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'false' ) ;
869
+ it ( 'should set aria-selected on each option for single select' , fakeAsync ( ( ) => {
870
+ expect ( options . every ( option => ! option . hasAttribute ( 'aria-selected' ) ) ) . toBe ( true ,
871
+ 'Expected all unselected single-select options not to have aria-selected set.' ) ;
874
872
875
873
options [ 1 ] . click ( ) ;
876
874
fixture . detectChanges ( ) ;
@@ -879,11 +877,44 @@ describe('MatSelect', () => {
879
877
fixture . detectChanges ( ) ;
880
878
flush ( ) ;
881
879
882
- expect ( options [ 0 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'false' ) ;
883
- expect ( options [ 1 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'true' ) ;
884
- expect ( options [ 2 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'false' ) ;
880
+ expect ( options [ 1 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'true' ,
881
+ 'Expected selected single-select option to have aria-selected="true".' ) ;
882
+ options . splice ( 1 , 1 ) ;
883
+ expect ( options . every ( option => ! option . hasAttribute ( 'aria-selected' ) ) ) . toBe ( true ,
884
+ 'Expected all unselected single-select options not to have aria-selected set.' ) ;
885
885
} ) ) ;
886
886
887
+ it ( 'should set aria-selected on each option for multi-select' , fakeAsync ( ( ) => {
888
+ fixture . destroy ( ) ;
889
+
890
+ const multiFixture = TestBed . createComponent ( MultiSelect ) ;
891
+ multiFixture . detectChanges ( ) ;
892
+
893
+ trigger = multiFixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement ;
894
+ trigger . click ( ) ;
895
+ multiFixture . detectChanges ( ) ;
896
+
897
+ options = Array . from ( overlayContainerElement . querySelectorAll ( 'mat-option' ) ) ;
898
+
899
+ expect ( options . every ( option => option . hasAttribute ( 'aria-selected' ) &&
900
+ option . getAttribute ( 'aria-selected' ) === 'false' ) ) . toBe ( true ,
901
+ 'Expected all unselected multi-select options to have aria-selected="false".' ) ;
902
+
903
+ options [ 1 ] . click ( ) ;
904
+ multiFixture . detectChanges ( ) ;
905
+
906
+ trigger . click ( ) ;
907
+ multiFixture . detectChanges ( ) ;
908
+ flush ( ) ;
909
+
910
+ expect ( options [ 1 ] . getAttribute ( 'aria-selected' ) ) . toEqual ( 'true' ,
911
+ 'Expected selected multi-select option to have aria-selected="true".' ) ;
912
+ options . splice ( 1 , 1 ) ;
913
+ expect ( options . every ( option => option . hasAttribute ( 'aria-selected' ) &&
914
+ option . getAttribute ( 'aria-selected' ) === 'false' ) ) . toBe ( true ,
915
+ 'Expected all unselected multi-select options to have aria-selected="false".' ) ;
916
+ } ) ) ;
917
+
887
918
it ( 'should set the tabindex of each option according to disabled state' , fakeAsync ( ( ) => {
888
919
expect ( options [ 0 ] . getAttribute ( 'tabindex' ) ) . toEqual ( '0' ) ;
889
920
expect ( options [ 1 ] . getAttribute ( 'tabindex' ) ) . toEqual ( '0' ) ;
0 commit comments