@ -10,7 +10,7 @@ import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms';
|
||||
import {Validators} from '@angular/forms/src/validators';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {of } from 'rxjs';
|
||||
|
||||
(function() {
|
||||
function asyncValidator(expected: string, timeouts = {}) {
|
||||
|
@ -8,7 +8,7 @@
|
||||
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';
|
||||
import {of } from 'rxjs';
|
||||
|
||||
(function() {
|
||||
function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ { return null; }
|
||||
|
@ -10,7 +10,7 @@ import {EventEmitter} from '@angular/core';
|
||||
import {async, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators} from '@angular/forms';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {of } from 'rxjs';
|
||||
|
||||
|
||||
(function() {
|
||||
|
@ -12,9 +12,8 @@ import {AbstractControl, AsyncValidator, AsyncValidatorFn, COMPOSITION_BUFFER_MO
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {merge} from 'rxjs/observable/merge';
|
||||
import {timer} from 'rxjs/observable/timer';
|
||||
import {_do} from 'rxjs/operator/do';
|
||||
import {merge, timer} from 'rxjs';
|
||||
import {tap} from 'rxjs/operators';
|
||||
|
||||
import {MyInput, MyInputForm} from './value_accessor_integration_spec';
|
||||
|
||||
@ -2433,7 +2432,7 @@ function uniqLoginAsyncValidator(expectedValue: string, timeout: number = 0) {
|
||||
|
||||
function observableValidator(resultArr: number[]): AsyncValidatorFn {
|
||||
return (c: AbstractControl) => {
|
||||
return _do.call(timer(100), (resp: any) => resultArr.push(resp));
|
||||
return timer(100).pipe(tap((resp: any) => resultArr.push(resp)));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,13 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Directive, Type, ViewChild, forwardRef} from '@angular/core';
|
||||
import {Component, Directive, Type, forwardRef} from '@angular/core';
|
||||
import {ComponentFixture, TestBed, async, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AbstractControl, AsyncValidator, COMPOSITION_BUFFER_MODE, FormControl, FormsModule, NG_ASYNC_VALIDATORS, NgForm, NgModel} from '@angular/forms';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {merge} from 'rxjs/observable/merge';
|
||||
import {merge} from 'rxjs';
|
||||
|
||||
import {NgModelCustomComp, NgModelCustomWrapper} from './value_accessor_integration_spec';
|
||||
|
||||
|
@ -11,11 +11,8 @@ import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, AsyncValidatorFn, FormArray, FormControl, Validators} from '@angular/forms';
|
||||
import {normalizeAsyncValidator} from '@angular/forms/src/directives/normalize_validator';
|
||||
import {AsyncValidator, ValidationErrors, ValidatorFn} from '@angular/forms/src/directives/validators';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {timer} from 'rxjs/observable/timer';
|
||||
import {first} from 'rxjs/operator/first';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {Observable, of , timer} from 'rxjs';
|
||||
import {first, map} from 'rxjs/operators';
|
||||
|
||||
(function() {
|
||||
function validator(key: string, error: any): ValidatorFn {
|
||||
@ -333,7 +330,8 @@ import {map} from 'rxjs/operator/map';
|
||||
[promiseValidator({'one': true}), promiseValidator({'two': true})]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
tick();
|
||||
|
||||
@ -345,7 +343,8 @@ import {map} from 'rxjs/operator/map';
|
||||
new AsyncValidatorDirective('expected', {'one': true}))]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
tick();
|
||||
|
||||
@ -356,7 +355,8 @@ import {map} from 'rxjs/operator/map';
|
||||
const v = Validators.composeAsync([promiseValidator({'one': true})]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('expected')))
|
||||
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
tick();
|
||||
|
||||
@ -367,7 +367,8 @@ import {map} from 'rxjs/operator/map';
|
||||
const v = Validators.composeAsync([promiseValidator({'one': true}), null !]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
tick();
|
||||
|
||||
@ -391,7 +392,8 @@ import {map} from 'rxjs/operator/map';
|
||||
[observableValidator({'one': true}), observableValidator({'two': true})]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
|
||||
expect(errorMap).toEqual({'one': true, 'two': true});
|
||||
@ -402,7 +404,8 @@ import {map} from 'rxjs/operator/map';
|
||||
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors) !;
|
||||
|
||||
expect(errorMap).toEqual({'one': true});
|
||||
@ -412,7 +415,8 @@ import {map} from 'rxjs/operator/map';
|
||||
const v = Validators.composeAsync([observableValidator({'one': true})]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('expected')))
|
||||
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
|
||||
expect(errorMap).toBeNull();
|
||||
@ -422,7 +426,8 @@ import {map} from 'rxjs/operator/map';
|
||||
const v = Validators.composeAsync([observableValidator({'one': true}), null !]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
|
||||
expect(errorMap).toEqual({'one': true});
|
||||
@ -430,14 +435,15 @@ import {map} from 'rxjs/operator/map';
|
||||
|
||||
it('should wait for all validators before setting errors', fakeAsync(() => {
|
||||
function getTimerObs(time: number, errorMap: {[key: string]: any}): AsyncValidatorFn {
|
||||
return (c: AbstractControl) => { return map.call(timer(time), () => errorMap); };
|
||||
return (c: AbstractControl) => { return timer(time).pipe(map(() => errorMap)); };
|
||||
}
|
||||
|
||||
const v = Validators.composeAsync(
|
||||
[getTimerObs(100, {one: true}), getTimerObs(200, {two: true})]) !;
|
||||
|
||||
let errorMap: {[key: string]: any} = undefined !;
|
||||
first.call(v(new FormControl('invalid')))
|
||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||
.pipe(first())
|
||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
||||
|
||||
tick(100);
|
||||
@ -448,7 +454,6 @@ import {map} from 'rxjs/operator/map';
|
||||
expect(errorMap).toEqual(
|
||||
{one: true, two: true}, `Expected errors to merge once all validators resolved.`);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user