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