@@ -2877,6 +2877,64 @@ describe('MatSelect', () => {
2877
2877
expect ( spy ) . toHaveBeenCalledWith ( 'steak-0' ) ;
2878
2878
} ) ) ;
2879
2879
2880
+ it ( 'should emit once when a reset value is selected' , fakeAsync ( ( ) => {
2881
+ const fixture = TestBed . createComponent ( BasicSelectWithoutForms ) ;
2882
+ const instance = fixture . componentInstance ;
2883
+ const spy = jasmine . createSpy ( 'change spy' ) ;
2884
+
2885
+ instance . selectedFood = 'sandwich-2' ;
2886
+ instance . foods [ 0 ] . value = null ;
2887
+ fixture . detectChanges ( ) ;
2888
+
2889
+ const subscription = instance . select . selectionChange . subscribe ( spy ) ;
2890
+
2891
+ fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
2892
+ fixture . detectChanges ( ) ;
2893
+ flush ( ) ;
2894
+
2895
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
2896
+ fixture . detectChanges ( ) ;
2897
+ flush ( ) ;
2898
+
2899
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
2900
+
2901
+ subscription . unsubscribe ( ) ;
2902
+ } ) ) ;
2903
+
2904
+ it ( 'should not emit the change event multiple times when a reset option is ' +
2905
+ 'selected twice in a row' , fakeAsync ( ( ) => {
2906
+ const fixture = TestBed . createComponent ( BasicSelectWithoutForms ) ;
2907
+ const instance = fixture . componentInstance ;
2908
+ const spy = jasmine . createSpy ( 'change spy' ) ;
2909
+
2910
+ instance . foods [ 0 ] . value = null ;
2911
+ fixture . detectChanges ( ) ;
2912
+
2913
+ const subscription = instance . select . selectionChange . subscribe ( spy ) ;
2914
+
2915
+ fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
2916
+ fixture . detectChanges ( ) ;
2917
+ flush ( ) ;
2918
+
2919
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
2920
+ fixture . detectChanges ( ) ;
2921
+ flush ( ) ;
2922
+
2923
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
2924
+
2925
+ fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
2926
+ fixture . detectChanges ( ) ;
2927
+ flush ( ) ;
2928
+
2929
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
2930
+ fixture . detectChanges ( ) ;
2931
+ flush ( ) ;
2932
+
2933
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
2934
+
2935
+ subscription . unsubscribe ( ) ;
2936
+ } ) ) ;
2937
+
2880
2938
} ) ;
2881
2939
2882
2940
describe ( 'with option centering disabled' , ( ) => {
0 commit comments