|
5 | 5 | * Use of this source code is governed by an MIT-style license that can be
|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 |
| - |
| 8 | +import {fakeAsync, tick} from '@angular/core/testing'; |
9 | 9 | import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
10 | 10 | import {FormBuilder} from '@angular/forms';
|
| 11 | +import {of } from 'rxjs/observable/of'; |
11 | 12 |
|
12 | 13 | (function() {
|
13 | 14 | function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; }
|
@@ -97,5 +98,26 @@ import {FormBuilder} from '@angular/forms';
|
97 | 98 | expect(a.validator).toBe(syncValidator);
|
98 | 99 | expect(a.asyncValidator).toBe(asyncValidator);
|
99 | 100 | });
|
| 101 | + |
| 102 | + it('should create control arrays with multiple async validators', fakeAsync(() => { |
| 103 | + function asyncValidator1() { return of ({'async1': true}); } |
| 104 | + function asyncValidator2() { return of ({'async2': true}); } |
| 105 | + |
| 106 | + const a = b.array(['one', 'two'], null, [asyncValidator1, asyncValidator2]); |
| 107 | + expect(a.value).toEqual(['one', 'two']); |
| 108 | + |
| 109 | + tick(); |
| 110 | + |
| 111 | + expect(a.errors).toEqual({'async1': true, 'async2': true}); |
| 112 | + })); |
| 113 | + |
| 114 | + it('should create control arrays with multiple sync validators', () => { |
| 115 | + function syncValidator1() { return {'sync1': true}; } |
| 116 | + function syncValidator2() { return {'sync2': true}; } |
| 117 | + |
| 118 | + const a = b.array(['one', 'two'], [syncValidator1, syncValidator2]); |
| 119 | + expect(a.value).toEqual(['one', 'two']); |
| 120 | + expect(a.errors).toEqual({'sync1': true, 'sync2': true}); |
| 121 | + }); |
100 | 122 | });
|
101 | 123 | })();
|
0 commit comments