@@ -3151,6 +3151,63 @@ describe('MatSelect', () => {
3151
3151
. toBeFalsy ( 'Expected no value after tabbing away.' ) ;
3152
3152
} ) ) ;
3153
3153
3154
+ it ( 'should emit once when a reset value is selected' , fakeAsync ( ( ) => {
3155
+ const fixture = TestBed . createComponent ( BasicSelectWithoutForms ) ;
3156
+ const instance = fixture . componentInstance ;
3157
+ const spy = jasmine . createSpy ( 'change spy' ) ;
3158
+
3159
+ instance . selectedFood = 'sandwich-2' ;
3160
+ instance . foods [ 0 ] . value = null ;
3161
+ fixture . detectChanges ( ) ;
3162
+
3163
+ const subscription = instance . select . selectionChange . subscribe ( spy ) ;
3164
+
3165
+ fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
3166
+ fixture . detectChanges ( ) ;
3167
+ flush ( ) ;
3168
+
3169
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
3170
+ fixture . detectChanges ( ) ;
3171
+ flush ( ) ;
3172
+
3173
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
3174
+
3175
+ subscription . unsubscribe ( ) ;
3176
+ } ) ) ;
3177
+
3178
+ it ( 'should not emit the change event multiple times when a reset option is ' +
3179
+ 'selected twice in a row' , fakeAsync ( ( ) => {
3180
+ const fixture = TestBed . createComponent ( BasicSelectWithoutForms ) ;
3181
+ const instance = fixture . componentInstance ;
3182
+ const spy = jasmine . createSpy ( 'change spy' ) ;
3183
+
3184
+ instance . foods [ 0 ] . value = null ;
3185
+ fixture . detectChanges ( ) ;
3186
+
3187
+ const subscription = instance . select . selectionChange . subscribe ( spy ) ;
3188
+
3189
+ fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
3190
+ fixture . detectChanges ( ) ;
3191
+ flush ( ) ;
3192
+
3193
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
3194
+ fixture . detectChanges ( ) ;
3195
+ flush ( ) ;
3196
+
3197
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
3198
+
3199
+ fixture . debugElement . query ( By . css ( '.mat-select-trigger' ) ) . nativeElement . click ( ) ;
3200
+ fixture . detectChanges ( ) ;
3201
+ flush ( ) ;
3202
+
3203
+ ( overlayContainerElement . querySelector ( 'mat-option' ) as HTMLElement ) . click ( ) ;
3204
+ fixture . detectChanges ( ) ;
3205
+ flush ( ) ;
3206
+
3207
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
3208
+
3209
+ subscription . unsubscribe ( ) ;
3210
+ } ) ) ;
3154
3211
3155
3212
} ) ;
3156
3213
0 commit comments