File tree 3 files changed +57
-11
lines changed
material-experimental/mdc-select
3 files changed +57
-11
lines changed Original file line number Diff line number Diff line change @@ -2709,11 +2709,34 @@ expect(panel.scrollTop)
2709
2709
describe ( `when the select's value is accessed on initialization` , ( ) => {
2710
2710
beforeEach ( waitForAsync ( ( ) => configureMatSelectTestingModule ( [ SelectEarlyAccessSibling ] ) ) ) ;
2711
2711
2712
- it ( 'should not throw when trying to access the selected value on init' , fakeAsync ( ( ) => {
2713
- expect ( ( ) => {
2714
- TestBed . createComponent ( SelectEarlyAccessSibling ) . detectChanges ( ) ;
2715
- } ) . not . toThrow ( ) ;
2716
- } ) ) ;
2712
+ it ( 'should not throw when trying to access the selected value on init in the view' ,
2713
+ fakeAsync ( ( ) => {
2714
+ expect ( ( ) => {
2715
+ TestBed . createComponent ( SelectEarlyAccessSibling ) . detectChanges ( ) ;
2716
+ } ) . not . toThrow ( ) ;
2717
+ } ) ) ;
2718
+
2719
+ it ( 'should not throw when reading selected value programmatically in single selection mode' ,
2720
+ fakeAsync ( ( ) => {
2721
+ expect ( ( ) => {
2722
+ const fixture = TestBed . createComponent ( SelectEarlyAccessSibling ) ;
2723
+ const select = fixture . debugElement . query ( By . directive ( MatSelect ) ) . componentInstance ;
2724
+ // We're checking that accessing the getter won't throw.
2725
+ select . multiple = false ;
2726
+ return select . selected ;
2727
+ } ) . not . toThrow ( ) ;
2728
+ } ) ) ;
2729
+
2730
+ it ( 'should not throw when reading selected value programmatically in multi selection mode' ,
2731
+ fakeAsync ( ( ) => {
2732
+ expect ( ( ) => {
2733
+ const fixture = TestBed . createComponent ( SelectEarlyAccessSibling ) ;
2734
+ const select = fixture . debugElement . query ( By . directive ( MatSelect ) ) . componentInstance ;
2735
+ // We're checking that accessing the getter won't throw.
2736
+ select . multiple = true ;
2737
+ return select . selected ;
2738
+ } ) . not . toThrow ( ) ;
2739
+ } ) ) ;
2717
2740
} ) ;
2718
2741
2719
2742
describe ( 'with ngIf and mat-label' , ( ) => {
Original file line number Diff line number Diff line change @@ -2776,11 +2776,34 @@ describe('MatSelect', () => {
2776
2776
describe ( `when the select's value is accessed on initialization` , ( ) => {
2777
2777
beforeEach ( waitForAsync ( ( ) => configureMatSelectTestingModule ( [ SelectEarlyAccessSibling ] ) ) ) ;
2778
2778
2779
- it ( 'should not throw when trying to access the selected value on init' , fakeAsync ( ( ) => {
2780
- expect ( ( ) => {
2781
- TestBed . createComponent ( SelectEarlyAccessSibling ) . detectChanges ( ) ;
2782
- } ) . not . toThrow ( ) ;
2783
- } ) ) ;
2779
+ it ( 'should not throw when trying to access the selected value on init in the view' ,
2780
+ fakeAsync ( ( ) => {
2781
+ expect ( ( ) => {
2782
+ TestBed . createComponent ( SelectEarlyAccessSibling ) . detectChanges ( ) ;
2783
+ } ) . not . toThrow ( ) ;
2784
+ } ) ) ;
2785
+
2786
+ it ( 'should not throw when reading selected value programmatically in single selection mode' ,
2787
+ fakeAsync ( ( ) => {
2788
+ expect ( ( ) => {
2789
+ const fixture = TestBed . createComponent ( SelectEarlyAccessSibling ) ;
2790
+ const select = fixture . debugElement . query ( By . directive ( MatSelect ) ) . componentInstance ;
2791
+ // We're checking that accessing the getter won't throw.
2792
+ select . multiple = false ;
2793
+ return select . selected ;
2794
+ } ) . not . toThrow ( ) ;
2795
+ } ) ) ;
2796
+
2797
+ it ( 'should not throw when reading selected value programmatically in multi selection mode' ,
2798
+ fakeAsync ( ( ) => {
2799
+ expect ( ( ) => {
2800
+ const fixture = TestBed . createComponent ( SelectEarlyAccessSibling ) ;
2801
+ const select = fixture . debugElement . query ( By . directive ( MatSelect ) ) . componentInstance ;
2802
+ // We're checking that accessing the getter won't throw.
2803
+ select . multiple = true ;
2804
+ return select . selected ;
2805
+ } ) . not . toThrow ( ) ;
2806
+ } ) ) ;
2784
2807
} ) ;
2785
2808
2786
2809
describe ( 'with ngIf and mat-label' , ( ) => {
Original file line number Diff line number Diff line change @@ -624,7 +624,7 @@ export abstract class _MatSelectBase<C> extends _MatSelectMixinBase implements A
624
624
625
625
/** The currently selected option. */
626
626
get selected ( ) : MatOption | MatOption [ ] {
627
- return this . multiple ? this . _selectionModel . selected : this . _selectionModel . selected [ 0 ] ;
627
+ return this . multiple ? this . _selectionModel ? .selected : this . _selectionModel ? .selected [ 0 ] ;
628
628
}
629
629
630
630
/** The value displayed in the trigger. */
You can’t perform that action at this time.
0 commit comments