fix(forms): fix Validators.min/maxLength with FormArray (#13095)
Fixes #13089
This commit is contained in:

committed by
Victor Berchet

parent
2e500cc85b
commit
e9f307f948
@ -8,7 +8,7 @@
|
||||
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {describe, expect, it} from '@angular/core/testing/testing_internal';
|
||||
import {AbstractControl, FormControl, Validators} from '@angular/forms';
|
||||
import {AbstractControl, FormArray, FormControl, Validators} from '@angular/forms';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {normalizeAsyncValidator} from '../src/directives/normalize_validator';
|
||||
@ -68,6 +68,18 @@ export function main() {
|
||||
'minlength': {'requiredLength': 2, 'actualLength': 1}
|
||||
});
|
||||
});
|
||||
|
||||
it('should not error when FormArray has valid length', () => {
|
||||
const fa = new FormArray([new FormControl(''), new FormControl('')]);
|
||||
expect(Validators.minLength(2)(fa)).toBeNull();
|
||||
});
|
||||
|
||||
it('should error when FormArray has invalid length', () => {
|
||||
const fa = new FormArray([new FormControl('')]);
|
||||
expect(Validators.minLength(2)(fa)).toEqual({
|
||||
'minlength': {'requiredLength': 2, 'actualLength': 1}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('maxLength', () => {
|
||||
@ -85,6 +97,18 @@ export function main() {
|
||||
'maxlength': {'requiredLength': 2, 'actualLength': 3}
|
||||
});
|
||||
});
|
||||
|
||||
it('should not error when FormArray has valid length', () => {
|
||||
const fa = new FormArray([new FormControl(''), new FormControl('')]);
|
||||
expect(Validators.maxLength(2)(fa)).toBeNull();
|
||||
});
|
||||
|
||||
it('should error when FormArray has invalid length', () => {
|
||||
const fa = new FormArray([new FormControl(''), new FormControl('')]);
|
||||
expect(Validators.maxLength(1)(fa)).toEqual({
|
||||
'maxlength': {'requiredLength': 1, 'actualLength': 2}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pattern', () => {
|
||||
|
Reference in New Issue
Block a user