@@ -75,7 +75,7 @@ describe('ControlValueAccessor', () => {
7575
7676 const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
7777 const control = fixture . componentInstance . control ;
78- const input = fixture . nativeElement . firstChild . firstChild ;
78+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
7979
8080 // Initial state
8181 expect ( control ( ) . value ) . toBe ( 'test' ) ;
@@ -92,6 +92,29 @@ describe('ControlValueAccessor', () => {
9292 expect ( fixture . componentInstance . f ( ) . value ( ) ) . toBe ( 'typing' ) ;
9393 } ) ;
9494
95+ it ( 'should mark field dirty on changes' , ( ) => {
96+ @Component ( {
97+ imports : [ Field , CustomControl ] ,
98+ template : `<custom-control [field]="f" />` ,
99+ } )
100+ class TestCmp {
101+ f = form < string > ( signal ( '' ) ) ;
102+ }
103+
104+ const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
105+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
106+ const field = fixture . componentInstance . f ;
107+
108+ expect ( field ( ) . dirty ( ) ) . toBe ( false ) ;
109+
110+ act ( ( ) => {
111+ input . value = 'typing' ;
112+ input . dispatchEvent ( new Event ( 'input' ) ) ;
113+ } ) ;
114+
115+ expect ( field ( ) . dirty ( ) ) . toBe ( true ) ;
116+ } ) ;
117+
95118 it ( 'should propagate touched events to field' , ( ) => {
96119 @Component ( {
97120 imports : [ Field , CustomControl ] ,
@@ -102,7 +125,7 @@ describe('ControlValueAccessor', () => {
102125 }
103126
104127 const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
105- const input = fixture . nativeElement . firstChild . firstChild ;
128+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
106129 expect ( fixture . componentInstance . f ( ) . touched ( ) ) . toBe ( false ) ;
107130
108131 act ( ( ) => input . dispatchEvent ( new Event ( 'blur' ) ) ) ;
@@ -122,7 +145,7 @@ describe('ControlValueAccessor', () => {
122145 }
123146
124147 const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
125- const input = fixture . nativeElement . firstChild . firstChild ;
148+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
126149 expect ( input . disabled ) . toBe ( false ) ;
127150
128151 act ( ( ) => enabled . set ( false ) ) ;
@@ -181,7 +204,7 @@ describe('ControlValueAccessor', () => {
181204
182205 const fixture = act ( ( ) => TestBed . createComponent ( TestCmp ) ) ;
183206 const control = fixture . componentInstance . control ;
184- const input = fixture . nativeElement . firstChild . firstChild ;
207+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
185208
186209 // Initial state
187210 expect ( control ( ) . value ) . toBe ( 'test' ) ;
0 commit comments