@@ -12,7 +12,7 @@ import {
12
12
} from '@angular/cdk/keycodes' ;
13
13
import { dispatchFakeEvent , dispatchKeyboardEvent , dispatchMouseEvent } from '@angular/cdk/testing' ;
14
14
import { Component , DebugElement , ViewChild } from '@angular/core' ;
15
- import { async , ComponentFixture , TestBed } from '@angular/core/testing' ;
15
+ import { async , ComponentFixture , TestBed , fakeAsync , flush } from '@angular/core/testing' ;
16
16
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
17
17
import { By , HAMMER_GESTURE_CONFIG } from '@angular/platform-browser' ;
18
18
import { MatSlider , MatSliderModule } from './index' ;
@@ -1274,6 +1274,23 @@ describe('MatSlider with forms module', () => {
1274
1274
1275
1275
expect ( testComponent . val ) . toBe ( 1 ) ;
1276
1276
} ) ;
1277
+
1278
+ it ( 'should be able to reset a slider by setting the model back to undefined' , fakeAsync ( ( ) => {
1279
+ expect ( testComponent . slider . value ) . toBe ( 0 ) ;
1280
+
1281
+ testComponent . val = 5 ;
1282
+ fixture . detectChanges ( ) ;
1283
+ flush ( ) ;
1284
+
1285
+ expect ( testComponent . slider . value ) . toBe ( 5 ) ;
1286
+
1287
+ testComponent . val = undefined ;
1288
+ fixture . detectChanges ( ) ;
1289
+ flush ( ) ;
1290
+
1291
+ expect ( testComponent . slider . value ) . toBe ( 0 ) ;
1292
+ } ) ) ;
1293
+
1277
1294
} ) ;
1278
1295
1279
1296
describe ( 'slider as a custom form control' , ( ) => {
@@ -1464,7 +1481,8 @@ class SliderWithFormControl {
1464
1481
styles : [ styles ] ,
1465
1482
} )
1466
1483
class SliderWithNgModel {
1467
- val = 0 ;
1484
+ @ViewChild ( MatSlider ) slider : MatSlider ;
1485
+ val : number | undefined = 0 ;
1468
1486
}
1469
1487
1470
1488
@Component ( {
0 commit comments