@@ -1472,6 +1472,36 @@ import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integrat
1472
1472
expect ( required . nativeElement . getAttribute ( 'pattern' ) ) . toEqual ( null ) ;
1473
1473
} ) ) ;
1474
1474
1475
+ it ( 'should update control status' , fakeAsync ( ( ) => {
1476
+ const fixture = initTest ( NgModelChangeState ) ;
1477
+ const inputEl = fixture . debugElement . query ( By . css ( 'input' ) ) ;
1478
+ const inputNativeEl = inputEl . nativeElement ;
1479
+ const onNgModelChange = jasmine . createSpy ( 'onNgModelChange' ) ;
1480
+ fixture . componentInstance . onNgModelChange = onNgModelChange ;
1481
+ fixture . detectChanges ( ) ;
1482
+ tick ( ) ;
1483
+
1484
+ expect ( onNgModelChange ) . not . toHaveBeenCalled ( ) ;
1485
+
1486
+ inputNativeEl . value = 'updated' ;
1487
+ onNgModelChange . and . callFake ( ( ngModel : NgModel ) => {
1488
+ expect ( ngModel . invalid ) . toBe ( true ) ;
1489
+ expect ( ngModel . value ) . toBe ( 'updated' ) ;
1490
+ } ) ;
1491
+ dispatchEvent ( inputNativeEl , 'input' ) ;
1492
+ expect ( onNgModelChange ) . toHaveBeenCalled ( ) ;
1493
+ tick ( ) ;
1494
+
1495
+ inputNativeEl . value = '333' ;
1496
+ onNgModelChange . and . callFake ( ( ngModel : NgModel ) => {
1497
+ expect ( ngModel . invalid ) . toBe ( false ) ;
1498
+ expect ( ngModel . value ) . toBe ( '333' ) ;
1499
+ } ) ;
1500
+ dispatchEvent ( inputNativeEl , 'input' ) ;
1501
+ expect ( onNgModelChange ) . toHaveBeenCalledTimes ( 2 ) ;
1502
+ tick ( ) ;
1503
+ } ) ) ;
1504
+
1475
1505
} ) ;
1476
1506
1477
1507
describe ( 'IME events' , ( ) => {
@@ -1809,6 +1839,17 @@ class NgModelChangesForm {
1809
1839
log ( ) { this . events . push ( 'fired' ) ; }
1810
1840
}
1811
1841
1842
+ @Component ( {
1843
+ selector : 'ng-model-change-state' ,
1844
+ template : `
1845
+ <input #ngModel="ngModel" ngModel [maxlength]="4"
1846
+ (ngModelChange)="onNgModelChange(ngModel)">
1847
+ `
1848
+ } )
1849
+ class NgModelChangeState {
1850
+ onNgModelChange = ( ) => { } ;
1851
+ }
1852
+
1812
1853
function sortedClassList ( el : HTMLElement ) {
1813
1854
const l = getDOM ( ) . classList ( el ) ;
1814
1855
l . sort ( ) ;
0 commit comments