feat(forms): multiple validators for array method (#20766)
Change array method signature so that array of validator and/or async validatior functions can be passed. Fixes #20665 PR Close #20766
This commit is contained in:
@ -5,9 +5,10 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {FormBuilder} from '@angular/forms';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
(function() {
|
||||
function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; }
|
||||
@ -97,5 +98,26 @@ import {FormBuilder} from '@angular/forms';
|
||||
expect(a.validator).toBe(syncValidator);
|
||||
expect(a.asyncValidator).toBe(asyncValidator);
|
||||
});
|
||||
|
||||
it('should create control arrays with multiple async validators', fakeAsync(() => {
|
||||
function asyncValidator1() { return of ({'async1': true}); }
|
||||
function asyncValidator2() { return of ({'async2': true}); }
|
||||
|
||||
const a = b.array(['one', 'two'], null, [asyncValidator1, asyncValidator2]);
|
||||
expect(a.value).toEqual(['one', 'two']);
|
||||
|
||||
tick();
|
||||
|
||||
expect(a.errors).toEqual({'async1': true, 'async2': true});
|
||||
}));
|
||||
|
||||
it('should create control arrays with multiple sync validators', () => {
|
||||
function syncValidator1() { return {'sync1': true}; }
|
||||
function syncValidator2() { return {'sync2': true}; }
|
||||
|
||||
const a = b.array(['one', 'two'], [syncValidator1, syncValidator2]);
|
||||
expect(a.value).toEqual(['one', 'two']);
|
||||
expect(a.errors).toEqual({'sync1': true, 'sync2': true});
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
Reference in New Issue
Block a user