@@ -1240,4 +1240,46 @@ describe('FormsManager', () => {
12401240 expect ( formsManager . getInitialValue ( 'other' ) ) . toBeUndefined ( ) ;
12411241 } ) ;
12421242 } ) ;
1243+
1244+ describe ( 'Debounce' , ( ) => {
1245+ it ( 'should update value after default debounce of 300ms for update on change controls' , fakeAsync ( ( ) => {
1246+ const updateOnChangeGroup = new FormGroup ( {
1247+ name : new FormControl ( null , { updateOn : 'change' } ) ,
1248+ } ) ;
1249+ formsManager . upsert ( 'updateOnChangeGroup' , updateOnChangeGroup ) ;
1250+
1251+ updateOnChangeGroup . get ( 'name' ) . patchValue ( 'Smith' ) ;
1252+
1253+ tick ( 100 ) ;
1254+ expect ( formsManager . getControl ( 'updateOnChangeGroup' , 'name' ) . value ) . toEqual ( null ) ;
1255+
1256+ tick ( 301 ) ;
1257+ expect ( formsManager . getControl ( 'updateOnChangeGroup' , 'name' ) . value ) . toEqual ( 'Smith' ) ;
1258+ } ) ) ;
1259+
1260+ it ( 'should skip debounce and update value immediately for a form group set to update on blur' , ( ) => {
1261+ const updateOnBlurGroup = new FormGroup (
1262+ {
1263+ name : new FormControl ( ) ,
1264+ } ,
1265+ { updateOn : 'blur' }
1266+ ) ;
1267+ formsManager . upsert ( 'updateOnBlurGroup' , updateOnBlurGroup ) ;
1268+
1269+ updateOnBlurGroup . get ( 'name' ) . patchValue ( 'Smith' ) ;
1270+
1271+ expect ( formsManager . getControl ( 'updateOnBlurGroup' , 'name' ) . value ) . toEqual ( 'Smith' ) ;
1272+ } ) ;
1273+
1274+ it ( 'should skip debounce and update value immediately for a form control set to update on blur' , ( ) => {
1275+ const updateOnBlurGroup = new FormGroup ( {
1276+ name : new FormControl ( null , { updateOn : 'blur' } ) ,
1277+ } ) ;
1278+ formsManager . upsert ( 'updateOnBlurGroup' , updateOnBlurGroup ) ;
1279+
1280+ updateOnBlurGroup . get ( 'name' ) . patchValue ( 'Smith' ) ;
1281+
1282+ expect ( formsManager . getControl ( 'updateOnBlurGroup' , 'name' ) . value ) . toEqual ( 'Smith' ) ;
1283+ } ) ;
1284+ } ) ;
12431285} ) ;
0 commit comments