1
1
import { Validators } from '@angular/forms' ;
2
2
import { expectTypeOf } from 'expect-type' ;
3
3
import { Observable , of , Subject , Subscription } from 'rxjs' ;
4
- import { ControlsOf , FormControl , FormGroup , ValuesOf } from '..' ;
4
+ import { ControlsOf , FormControl , FormGroup } from '..' ;
5
5
import { ControlState } from './core' ;
6
6
import { FormArray } from './form-array' ;
7
7
@@ -224,6 +224,13 @@ const createArray = (withError = false) => {
224
224
) ;
225
225
} ;
226
226
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
+
227
234
describe ( 'FormArray Functionality' , ( ) => {
228
235
it ( 'should valueChanges$' , ( ) => {
229
236
const control = createArray ( ) ;
@@ -240,6 +247,25 @@ describe('FormArray Functionality', () => {
240
247
expect ( spy ) . toHaveBeenCalledWith ( [ '1' , '3' , '' ] ) ;
241
248
} ) ;
242
249
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
+
243
269
it ( 'should disabledChanges$' , ( ) => {
244
270
const control = createArray ( ) ;
245
271
const spy = jest . fn ( ) ;
0 commit comments