11import { Validators } from '@angular/forms' ;
22import { expectTypeOf } from 'expect-type' ;
33import { Observable , of , Subject , Subscription } from 'rxjs' ;
4- import { ControlsOf , FormControl , FormGroup , ValuesOf } from '..' ;
4+ import { ControlsOf , FormControl , FormGroup } from '..' ;
55import { ControlState } from './core' ;
66import { FormArray } from './form-array' ;
77
@@ -224,6 +224,13 @@ const createArray = (withError = false) => {
224224 ) ;
225225} ;
226226
227+ const createInvalidArray = ( withError = false ) => {
228+ return new FormArray < string | null > (
229+ [ new FormControl ( null , Validators . required ) , new FormControl ( null , Validators . required ) ] ,
230+ withError ? errorFn : [ ]
231+ ) ;
232+ } ;
233+
227234describe ( 'FormArray Functionality' , ( ) => {
228235 it ( 'should valueChanges$' , ( ) => {
229236 const control = createArray ( ) ;
@@ -240,6 +247,25 @@ describe('FormArray Functionality', () => {
240247 expect ( spy ) . toHaveBeenCalledWith ( [ '1' , '3' , '' ] ) ;
241248 } ) ;
242249
250+ it ( 'should validValueChanges$' , ( ) => {
251+ const control = createInvalidArray ( ) ;
252+ const spy = jest . fn ( ) ;
253+ control . validValue$ . subscribe ( spy ) ;
254+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
255+ control . patchValue ( [ '1' , '2' ] ) ;
256+ expect ( spy ) . toHaveBeenCalledTimes ( 2 ) ;
257+ expect ( spy ) . toHaveBeenCalledWith ( [ '1' , '2' ] ) ;
258+ control . push ( new FormControl ( '3' , Validators . required ) ) ;
259+ expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
260+ expect ( spy ) . toHaveBeenCalledWith ( [ '1' , '2' , '3' ] ) ;
261+ control . push ( new FormControl ( null , Validators . required ) ) ;
262+ expect ( spy ) . toHaveBeenCalledTimes ( 3 ) ;
263+ expect ( spy ) . not . toHaveReturnedWith ( [ '1' , '2' , '3' , null ] ) ;
264+ control . removeAt ( 3 ) ;
265+ expect ( spy ) . toHaveBeenCalledTimes ( 4 ) ;
266+ expect ( spy ) . toHaveBeenCalledWith ( [ '1' , '2' , '3' ] ) ;
267+ } ) ;
268+
243269 it ( 'should disabledChanges$' , ( ) => {
244270 const control = createArray ( ) ;
245271 const spy = jest . fn ( ) ;
0 commit comments