@@ -71,6 +71,30 @@ describe('FormControlDirective with FVC', () => {
7171 expect ( fixture . componentInstance . ctrl . value ) . toBe ( 'from-fvc' ) ;
7272 } ) ;
7373
74+ it ( 'should update FormControl value before template (valueChange) listener fires' , ( ) => {
75+ @Component ( {
76+ template : `<my-fvc-input [formControl]="ctrl" (valueChange)="onValueChange()" />` ,
77+ imports : [ MyFvcInput , ReactiveFormsModule ] ,
78+ } )
79+ class TestCmp {
80+ ctrl = new FormControl ( 'initial' ) ;
81+ observedDuringValueChange : string | null | undefined ;
82+
83+ onValueChange ( ) {
84+ this . observedDuringValueChange = this . ctrl . value ;
85+ }
86+ }
87+
88+ const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
89+ const component = fixture . componentInstance ;
90+ const fvc = fixture . debugElement . query ( By . directive ( MyFvcInput ) ) . componentInstance ;
91+
92+ act ( ( ) => fvc . value . set ( 'from-fvc' ) ) ;
93+
94+ expect ( component . observedDuringValueChange ) . toBe ( 'from-fvc' ) ;
95+ expect ( component . ctrl . value ) . toBe ( 'from-fvc' ) ;
96+ } ) ;
97+
7498 it ( 'should fall back to CVA when no FVC pattern is present' , ( ) => {
7599 @Component ( {
76100 template : `<input [formControl]="ctrl" />` ,
@@ -553,6 +577,36 @@ describe('FormControlName with FVC', () => {
553577 expect ( fixture . componentInstance . form . controls . name . value ) . toBe ( 'from-fvc' ) ;
554578 } ) ;
555579
580+ it ( 'should update FormControl value before template (valueChange) listener fires' , ( ) => {
581+ @Component ( {
582+ template : `
583+ <form [formGroup]="form">
584+ <my-fvc-input formControlName="name" (valueChange)="onValueChange()" />
585+ </form>
586+ ` ,
587+ imports : [ MyFvcInput , ReactiveFormsModule ] ,
588+ } )
589+ class TestCmp {
590+ form = new FormGroup ( {
591+ name : new FormControl ( 'initial' ) ,
592+ } ) ;
593+ observedDuringValueChange : string | null | undefined ;
594+
595+ onValueChange ( ) {
596+ this . observedDuringValueChange = this . form . controls . name . value ;
597+ }
598+ }
599+
600+ const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
601+ const component = fixture . componentInstance ;
602+ const fvc = fixture . debugElement . query ( By . directive ( MyFvcInput ) ) . componentInstance ;
603+
604+ act ( ( ) => fvc . value . set ( 'from-fvc' ) ) ;
605+
606+ expect ( component . observedDuringValueChange ) . toBe ( 'from-fvc' ) ;
607+ expect ( component . form . controls . name . value ) . toBe ( 'from-fvc' ) ;
608+ } ) ;
609+
556610 it ( 'should fall back to CVA when no FVC pattern is present' , ( ) => {
557611 @Component ( {
558612 template : `
0 commit comments