Revert "fix(forms): Update types for TypeScript nullability support (#15859)" (#15977)

This reverts commit 6a2e08d0a8.
This commit is contained in:
Tobias Bosch
2017-04-13 18:03:42 -07:00
committed by GitHub
parent 6a2e08d0a8
commit 2e47a0d19f
27 changed files with 330 additions and 343 deletions

View File

@ -28,7 +28,7 @@ class CustomValidatorDirective implements Validator {
function asyncValidator(expected: any, timeout = 0) {
return (c: AbstractControl): any => {
let resolve: (result: any) => void = undefined !;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const res = c.value != expected ? {'async': true} : null;
if (timeout == 0) {
@ -44,7 +44,7 @@ export function main() {
describe('Form Directives', () => {
let defaultAccessor: DefaultValueAccessor;
beforeEach(() => { defaultAccessor = new DefaultValueAccessor(null !, null !, null !); });
beforeEach(() => { defaultAccessor = new DefaultValueAccessor(null, null, null); });
describe('shared', () => {
describe('selectValueAccessor', () => {
@ -59,42 +59,42 @@ export function main() {
() => { expect(selectValueAccessor(dir, [defaultAccessor])).toEqual(defaultAccessor); });
it('should return checkbox accessor when provided', () => {
const checkboxAccessor = new CheckboxControlValueAccessor(null !, null !);
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [
defaultAccessor, checkboxAccessor
])).toEqual(checkboxAccessor);
});
it('should return select accessor when provided', () => {
const selectAccessor = new SelectControlValueAccessor(null !, null !);
const selectAccessor = new SelectControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [
defaultAccessor, selectAccessor
])).toEqual(selectAccessor);
});
it('should return select multiple accessor when provided', () => {
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null !, null !);
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null, null);
expect(selectValueAccessor(dir, [
defaultAccessor, selectMultipleAccessor
])).toEqual(selectMultipleAccessor);
});
it('should throw when more than one build-in accessor is provided', () => {
const checkboxAccessor = new CheckboxControlValueAccessor(null !, null !);
const selectAccessor = new SelectControlValueAccessor(null !, null !);
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
const selectAccessor = new SelectControlValueAccessor(null, null);
expect(() => selectValueAccessor(dir, [checkboxAccessor, selectAccessor])).toThrowError();
});
it('should return custom accessor when provided', () => {
const customAccessor = new SpyValueAccessor();
const checkboxAccessor = new CheckboxControlValueAccessor(null !, null !);
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
expect(selectValueAccessor(dir, <any>[defaultAccessor, customAccessor, checkboxAccessor]))
.toEqual(customAccessor);
});
it('should return custom accessor when provided with select multiple', () => {
const customAccessor = new SpyValueAccessor();
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null !, null !);
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null, null);
expect(selectValueAccessor(
dir, <any>[defaultAccessor, customAccessor, selectMultipleAccessor]))
.toEqual(customAccessor);
@ -110,13 +110,13 @@ export function main() {
it('should compose functions', () => {
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
const dummy2 = (_: any /** TODO #9100 */) => ({'dummy2': true});
const v = composeValidators([dummy1, dummy2]) !;
const v = composeValidators([dummy1, dummy2]);
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'dummy2': true});
});
it('should compose validator directives', () => {
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
const v = composeValidators([dummy1, new CustomValidatorDirective()]) !;
const v = composeValidators([dummy1, new CustomValidatorDirective()]);
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'custom': true});
});
});
@ -168,7 +168,7 @@ export function main() {
describe('addControl', () => {
it('should throw when no control found', () => {
const dir = new FormControlName(form, null !, null !, [defaultAccessor]);
const dir = new FormControlName(form, null, null, [defaultAccessor]);
dir.name = 'invalidName';
expect(() => form.addControl(dir))
@ -176,7 +176,7 @@ export function main() {
});
it('should throw for a named control when no value accessor', () => {
const dir = new FormControlName(form, null !, null !, null !);
const dir = new FormControlName(form, null, null, null);
dir.name = 'login';
expect(() => form.addControl(dir))
@ -184,8 +184,8 @@ export function main() {
});
it('should throw when no value accessor with path', () => {
const group = new FormGroupName(form, null !, null !);
const dir = new FormControlName(group, null !, null !, null !);
const group = new FormGroupName(form, null, null);
const dir = new FormControlName(group, null, null, null);
group.name = 'passwords';
dir.name = 'password';
@ -315,7 +315,7 @@ export function main() {
personControlGroupDir = new NgModelGroup(form, [], []);
personControlGroupDir.name = 'person';
loginControlDir = new NgModel(personControlGroupDir, null !, null !, [defaultAccessor]);
loginControlDir = new NgModel(personControlGroupDir, null, null, [defaultAccessor]);
loginControlDir.name = 'login';
loginControlDir.valueAccessor = new DummyControlValueAccessor();
});
@ -534,7 +534,7 @@ export function main() {
beforeEach(() => {
ngModel = new NgModel(
null !, [Validators.required], [asyncValidator('expected')], [defaultAccessor]);
null, [Validators.required], [asyncValidator('expected')], [defaultAccessor]);
ngModel.valueAccessor = new DummyControlValueAccessor();
control = ngModel.control;
});
@ -566,7 +566,7 @@ export function main() {
});
it('should throw when no value accessor with named control', () => {
const namedDir = new NgModel(null !, null !, null !, null !);
const namedDir = new NgModel(null, null, null, null);
namedDir.name = 'one';
expect(() => namedDir.ngOnChanges({}))
@ -574,7 +574,7 @@ export function main() {
});
it('should throw when no value accessor with unnamed control', () => {
const unnamedDir = new NgModel(null !, null !, null !, null !);
const unnamedDir = new NgModel(null, null, null, null);
expect(() => unnamedDir.ngOnChanges({}))
.toThrowError(

View File

@ -15,7 +15,7 @@ import {Validators} from '../src/validators';
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: AbstractControl) => {
let resolve: (result: any) => void = undefined !;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
@ -89,7 +89,7 @@ export function main() {
new FormGroup({'c2': new FormControl('v2'), 'c3': new FormControl('v3')}),
new FormArray([new FormControl('v4'), new FormControl('v5')])
]);
a.at(0).get('c3') !.disable();
a.at(0).get('c3').disable();
(a.at(1) as FormArray).at(1).disable();
expect(a.getRawValue()).toEqual([{'c2': 'v2', 'c3': 'v3'}, ['v4', 'v5']]);
@ -693,7 +693,7 @@ export function main() {
describe('get', () => {
it('should return null when path is null', () => {
const g = new FormGroup({});
expect(g.get(null !)).toEqual(null);
expect(g.get(null)).toEqual(null);
});
it('should return null when path is empty', () => {
@ -712,23 +712,23 @@ export function main() {
'nested': new FormGroup({'two': new FormControl('222')})
});
expect(g.get(['one']) !.value).toEqual('111');
expect(g.get('one') !.value).toEqual('111');
expect(g.get(['nested', 'two']) !.value).toEqual('222');
expect(g.get('nested.two') !.value).toEqual('222');
expect(g.get(['one']).value).toEqual('111');
expect(g.get('one').value).toEqual('111');
expect(g.get(['nested', 'two']).value).toEqual('222');
expect(g.get('nested.two').value).toEqual('222');
});
it('should return an element of an array', () => {
const g = new FormGroup({'array': new FormArray([new FormControl('111')])});
expect(g.get(['array', 0]) !.value).toEqual('111');
expect(g.get(['array', 0]).value).toEqual('111');
});
});
describe('asyncValidator', () => {
it('should run the async validator', fakeAsync(() => {
const c = new FormControl('value');
const g = new FormArray([c], null !, asyncValidator('expected'));
const g = new FormArray([c], null, asyncValidator('expected'));
expect(g.pending).toEqual(true);
@ -793,10 +793,10 @@ export function main() {
});
expect(g.valid).toBe(false);
g.get('nested') !.disable();
g.get('nested').disable();
expect(g.valid).toBe(true);
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.valid).toBe(false);
});
@ -805,36 +805,36 @@ export function main() {
{nested: new FormArray([new FormControl('one')]), two: new FormControl('two')});
expect(g.value).toEqual({'nested': ['one'], 'two': 'two'});
g.get('nested') !.disable();
g.get('nested').disable();
expect(g.value).toEqual({'two': 'two'});
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.value).toEqual({'nested': ['one'], 'two': 'two'});
});
it('should ignore disabled controls when determining dirtiness', () => {
const g = new FormGroup({nested: a, two: new FormControl('two')});
g.get(['nested', 0]) !.markAsDirty();
g.get(['nested', 0]).markAsDirty();
expect(g.dirty).toBe(true);
g.get('nested') !.disable();
expect(g.get('nested') !.dirty).toBe(true);
g.get('nested').disable();
expect(g.get('nested').dirty).toBe(true);
expect(g.dirty).toEqual(false);
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.dirty).toEqual(true);
});
it('should ignore disabled controls when determining touched state', () => {
const g = new FormGroup({nested: a, two: new FormControl('two')});
g.get(['nested', 0]) !.markAsTouched();
g.get(['nested', 0]).markAsTouched();
expect(g.touched).toBe(true);
g.get('nested') !.disable();
expect(g.get('nested') !.touched).toBe(true);
g.get('nested').disable();
expect(g.get('nested').touched).toBe(true);
expect(g.touched).toEqual(false);
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.touched).toEqual(true);
});
@ -901,7 +901,7 @@ export function main() {
});
it('should clear out async array errors when disabled', fakeAsync(() => {
const arr = new FormArray([new FormControl()], null !, asyncValidator('expected'));
const arr = new FormArray([new FormControl()], null, asyncValidator('expected'));
tick();
expect(arr.errors).toEqual({'async': true});
@ -914,7 +914,7 @@ export function main() {
}));
it('should re-populate async array errors when enabled from a child', fakeAsync(() => {
const arr = new FormArray([new FormControl()], null !, asyncValidator('expected'));
const arr = new FormArray([new FormControl()], null, asyncValidator('expected'));
tick();
expect(arr.errors).toEqual({'async': true});
@ -988,7 +988,7 @@ export function main() {
});
it('should remove control if new control is null', () => {
a.setControl(0, null !);
a.setControl(0, null);
expect(a.controls[0]).not.toBeDefined();
expect(a.value).toEqual([]);
});

View File

@ -16,7 +16,7 @@ import {FormArray} from '../src/model';
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: FormControl) => {
let resolve: (result: any) => void = undefined !;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
@ -49,7 +49,7 @@ export function main() {
describe('boxed values', () => {
it('should support valid boxed values on creation', () => {
const c = new FormControl({value: 'some val', disabled: true}, null !, null !);
const c = new FormControl({value: 'some val', disabled: true}, null, null);
expect(c.disabled).toBe(true);
expect(c.value).toBe('some val');
expect(c.status).toBe('DISABLED');
@ -63,13 +63,13 @@ export function main() {
});
it('should not treat objects as boxed values if they have more than two props', () => {
const c = new FormControl({value: '', disabled: true, test: 'test'}, null !, null !);
const c = new FormControl({value: '', disabled: true, test: 'test'}, null, null);
expect(c.value).toEqual({value: '', disabled: true, test: 'test'});
expect(c.disabled).toBe(false);
});
it('should not treat objects as boxed values if disabled is missing', () => {
const c = new FormControl({value: '', test: 'test'}, null !, null !);
const c = new FormControl({value: '', test: 'test'}, null, null);
expect(c.value).toEqual({value: '', test: 'test'});
expect(c.disabled).toBe(false);
});
@ -156,7 +156,7 @@ export function main() {
describe('asyncValidator', () => {
it('should run validator with the initial value', fakeAsync(() => {
const c = new FormControl('value', null !, asyncValidator('expected'));
const c = new FormControl('value', null, asyncValidator('expected'));
tick();
expect(c.valid).toEqual(false);
@ -164,7 +164,7 @@ export function main() {
}));
it('should support validators returning observables', fakeAsync(() => {
const c = new FormControl('value', null !, asyncValidatorReturningObservable);
const c = new FormControl('value', null, asyncValidatorReturningObservable);
tick();
expect(c.valid).toEqual(false);
@ -172,7 +172,7 @@ export function main() {
}));
it('should rerun the validator when the value changes', fakeAsync(() => {
const c = new FormControl('value', null !, asyncValidator('expected'));
const c = new FormControl('value', null, asyncValidator('expected'));
c.setValue('expected');
tick();
@ -193,7 +193,7 @@ export function main() {
}));
it('should mark the control as pending while running the async validation', fakeAsync(() => {
const c = new FormControl('', null !, asyncValidator('expected'));
const c = new FormControl('', null, asyncValidator('expected'));
expect(c.pending).toEqual(true);
@ -204,7 +204,7 @@ export function main() {
it('should only use the latest async validation run', fakeAsync(() => {
const c = new FormControl(
'', null !, asyncValidator('expected', {'long': 200, 'expected': 100}));
'', null, asyncValidator('expected', {'long': 200, 'expected': 100}));
c.setValue('long');
c.setValue('expected');
@ -216,14 +216,14 @@ export function main() {
it('should support arrays of async validator functions if passed', fakeAsync(() => {
const c =
new FormControl('value', null !, [asyncValidator('expected'), otherAsyncValidator]);
new FormControl('value', null, [asyncValidator('expected'), otherAsyncValidator]);
tick();
expect(c.errors).toEqual({'async': true, 'other': true});
}));
it('should add single async validator', fakeAsync(() => {
const c = new FormControl('value', null !);
const c = new FormControl('value', null);
c.setAsyncValidators(asyncValidator('expected'));
expect(c.asyncValidator).not.toEqual(null);
@ -235,7 +235,7 @@ export function main() {
}));
it('should add async validator from array', fakeAsync(() => {
const c = new FormControl('value', null !);
const c = new FormControl('value', null);
c.setAsyncValidators([asyncValidator('expected')]);
expect(c.asyncValidator).not.toEqual(null);
@ -634,7 +634,8 @@ export function main() {
tick();
expect(log).toEqual([
'value: \'\'',
'' +
'value: \'\'',
'status: \'INVALID\'',
'value: \'nonEmpty\'',
'status: \'PENDING\'',
@ -934,7 +935,7 @@ export function main() {
});
it('should clear out async errors when disabled', fakeAsync(() => {
const c = new FormControl('', null !, asyncValidator('expected'));
const c = new FormControl('', null, asyncValidator('expected'));
tick();
expect(c.errors).toEqual({'async': true});

View File

@ -15,7 +15,7 @@ import {AbstractControl, FormArray, FormControl, FormGroup, Validators} from '@a
export function main() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: AbstractControl) => {
let resolve: (result: any) => void = undefined !;
let resolve: (result: any) => void;
const promise = new Promise(res => { resolve = res; });
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
const res = c.value != expected ? {'async': true} : null;
@ -70,7 +70,7 @@ export function main() {
'group': new FormGroup({'c2': new FormControl('v2'), 'c3': new FormControl('v3')}),
'array': new FormArray([new FormControl('v4'), new FormControl('v5')])
});
fg.get('group') !.get('c3') !.disable();
fg.get('group').get('c3').disable();
(fg.get('array') as FormArray).at(1).disable();
expect(fg.getRawValue())
@ -690,7 +690,7 @@ export function main() {
describe('asyncValidator', () => {
it('should run the async validator', fakeAsync(() => {
const c = new FormControl('value');
const g = new FormGroup({'one': c}, null !, asyncValidator('expected'));
const g = new FormGroup({'one': c}, null, asyncValidator('expected'));
expect(g.pending).toEqual(true);
@ -701,7 +701,7 @@ export function main() {
}));
it('should set the parent group\'s status to pending', fakeAsync(() => {
const c = new FormControl('value', null !, asyncValidator('expected'));
const c = new FormControl('value', null, asyncValidator('expected'));
const g = new FormGroup({'one': c});
expect(g.pending).toEqual(true);
@ -713,13 +713,13 @@ export function main() {
it('should run the parent group\'s async validator when children are pending',
fakeAsync(() => {
const c = new FormControl('value', null !, asyncValidator('expected'));
const g = new FormGroup({'one': c}, null !, asyncValidator('expected'));
const c = new FormControl('value', null, asyncValidator('expected'));
const g = new FormGroup({'one': c}, null, asyncValidator('expected'));
tick(1);
expect(g.errors).toEqual({'async': true});
expect(g.get('one') !.errors).toEqual({'async': true});
expect(g.get('one').errors).toEqual({'async': true});
}));
});
@ -772,10 +772,10 @@ export function main() {
});
expect(g.valid).toBe(false);
g.get('nested') !.disable();
g.get('nested').disable();
expect(g.valid).toBe(true);
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.valid).toBe(false);
});
@ -784,10 +784,10 @@ export function main() {
{nested: new FormGroup({one: new FormControl('one')}), two: new FormControl('two')});
expect(g.value).toEqual({'nested': {'one': 'one'}, 'two': 'two'});
g.get('nested') !.disable();
g.get('nested').disable();
expect(g.value).toEqual({'two': 'two'});
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.value).toEqual({'nested': {'one': 'one'}, 'two': 'two'});
});
@ -795,13 +795,13 @@ export function main() {
const g = new FormGroup(
{nested: new FormGroup({one: new FormControl('one'), two: new FormControl('two')})});
g.get('nested.two') !.disable();
g.get('nested.two').disable();
expect(g.value).toEqual({nested: {one: 'one'}});
g.get('nested') !.disable();
g.get('nested').disable();
expect(g.value).toEqual({nested: {one: 'one', two: 'two'}});
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.value).toEqual({nested: {one: 'one', two: 'two'}});
});
@ -809,38 +809,38 @@ export function main() {
const g = new FormGroup(
{nested: new FormGroup({one: new FormControl('one'), two: new FormControl('two')})});
g.get('nested.two') !.disable();
g.get('nested.two').disable();
expect(g.value).toEqual({nested: {one: 'one'}});
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.value).toEqual({nested: {one: 'one', two: 'two'}});
});
it('should ignore disabled controls when determining dirtiness', () => {
const g = new FormGroup(
{nested: new FormGroup({one: new FormControl('one')}), two: new FormControl('two')});
g.get('nested.one') !.markAsDirty();
g.get('nested.one').markAsDirty();
expect(g.dirty).toBe(true);
g.get('nested') !.disable();
expect(g.get('nested') !.dirty).toBe(true);
g.get('nested').disable();
expect(g.get('nested').dirty).toBe(true);
expect(g.dirty).toEqual(false);
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.dirty).toEqual(true);
});
it('should ignore disabled controls when determining touched state', () => {
const g = new FormGroup(
{nested: new FormGroup({one: new FormControl('one')}), two: new FormControl('two')});
g.get('nested.one') !.markAsTouched();
g.get('nested.one').markAsTouched();
expect(g.touched).toBe(true);
g.get('nested') !.disable();
expect(g.get('nested') !.touched).toBe(true);
g.get('nested').disable();
expect(g.get('nested').touched).toBe(true);
expect(g.touched).toEqual(false);
g.get('nested') !.enable();
g.get('nested').enable();
expect(g.touched).toEqual(true);
});
@ -907,8 +907,7 @@ export function main() {
});
it('should clear out async group errors when disabled', fakeAsync(() => {
const g =
new FormGroup({'one': new FormControl()}, null !, asyncValidator('expected'));
const g = new FormGroup({'one': new FormControl()}, null, asyncValidator('expected'));
tick();
expect(g.errors).toEqual({'async': true});
@ -921,8 +920,7 @@ export function main() {
}));
it('should re-populate async group errors when enabled from a child', fakeAsync(() => {
const g =
new FormGroup({'one': new FormControl()}, null !, asyncValidator('expected'));
const g = new FormGroup({'one': new FormControl()}, null, asyncValidator('expected'));
tick();
expect(g.errors).toEqual({'async': true});
@ -1030,7 +1028,7 @@ export function main() {
});
it('should remove control if new control is null', () => {
g.setControl('one', null !);
g.setControl('one', null);
expect(g.controls['one']).not.toBeDefined();
expect(g.value).toEqual({});
});

View File

@ -166,7 +166,7 @@ export function main() {
});
fixture.componentInstance.form = form;
fixture.detectChanges();
expect(form.get('login') !.errors).toEqual({required: true});
expect(form.get('login').errors).toEqual({required: true});
const newForm = new FormGroup({
'login': new FormControl(''),
@ -177,7 +177,7 @@ export function main() {
fixture.componentInstance.form = newForm;
fixture.detectChanges();
expect(newForm.get('login') !.errors).toEqual({required: true});
expect(newForm.get('login').errors).toEqual({required: true});
});
it('should pick up dir validators from nested form groups', () => {
@ -188,7 +188,7 @@ export function main() {
});
fixture.componentInstance.form = form;
fixture.detectChanges();
expect(form.get('signin') !.valid).toBe(false);
expect(form.get('signin').valid).toBe(false);
const newForm = new FormGroup({
'signin':
@ -197,7 +197,7 @@ export function main() {
fixture.componentInstance.form = newForm;
fixture.detectChanges();
expect(form.get('signin') !.valid).toBe(false);
expect(form.get('signin').valid).toBe(false);
});
it('should strip named controls that are not found', () => {
@ -373,7 +373,7 @@ export function main() {
it('should throw an error if compareWith is not a function', () => {
const fixture = initTest(FormControlSelectWithCompareFn);
fixture.componentInstance.compareFn = null !;
fixture.componentInstance.compareFn = null;
expect(() => fixture.detectChanges())
.toThrowError(/compareWith must be a function, but received null/);
});
@ -412,7 +412,7 @@ export function main() {
it('should throw an error when compareWith is not a function', () => {
const fixture = initTest(FormControlSelectMultipleWithCompareFn);
fixture.componentInstance.compareFn = null !;
fixture.componentInstance.compareFn = null;
expect(() => fixture.detectChanges())
.toThrowError(/compareWith must be a function, but received null/);
});
@ -623,7 +623,7 @@ export function main() {
it('should emit ngSubmit event with the original submit event on submit', () => {
const fixture = initTest(FormGroupComp);
fixture.componentInstance.form = new FormGroup({'login': new FormControl('loginValue')});
fixture.componentInstance.event = null !;
fixture.componentInstance.event = null;
fixture.detectChanges();
const formEl = fixture.debugElement.query(By.css('form')).nativeElement;
@ -739,7 +739,7 @@ export function main() {
it('should work with single fields and async validators', fakeAsync(() => {
const fixture = initTest(FormControlComp);
const control = new FormControl('', null !, uniqLoginAsyncValidator('good'));
const control = new FormControl('', null, uniqLoginAsyncValidator('good'));
fixture.debugElement.componentInstance.control = control;
fixture.detectChanges();
@ -995,10 +995,10 @@ export function main() {
fixture.detectChanges();
// view -> model
expect(form.get('food') !.value).toEqual('chicken');
expect(form.get('food').value).toEqual('chicken');
expect(inputs[1].nativeElement.checked).toEqual(false);
form.get('food') !.setValue('fish');
form.get('food').setValue('fish');
fixture.detectChanges();
// programmatic change -> view
@ -1039,16 +1039,16 @@ export function main() {
fixture.componentInstance.form = form;
fixture.detectChanges();
form.get('food') !.setValue(null);
form.get('food').setValue(null);
fixture.detectChanges();
const inputs = fixture.debugElement.queryAll(By.css('input'));
expect(inputs[0].nativeElement.checked).toEqual(false);
form.get('food') !.setValue('chicken');
form.get('food').setValue('chicken');
fixture.detectChanges();
form.get('food') !.setValue(undefined);
form.get('food').setValue(undefined);
fixture.detectChanges();
expect(inputs[0].nativeElement.checked).toEqual(false);
});
@ -1139,8 +1139,8 @@ export function main() {
fixture.detectChanges();
// view -> model
expect(form.get('food') !.value).toEqual('chicken');
expect(form.get('nested.food') !.value).toEqual('fish');
expect(form.get('food').value).toEqual('chicken');
expect(form.get('nested.food').value).toEqual('fish');
expect(inputs[1].nativeElement.checked).toEqual(false);
expect(inputs[2].nativeElement.checked).toEqual(false);
@ -1161,7 +1161,7 @@ export function main() {
expect(inputs[2].nativeElement.disabled).toEqual(false);
expect(inputs[3].nativeElement.disabled).toEqual(false);
form.get('food') !.disable();
form.get('food').disable();
expect(inputs[0].nativeElement.disabled).toEqual(true);
expect(inputs[1].nativeElement.disabled).toEqual(true);
expect(inputs[2].nativeElement.disabled).toEqual(false);
@ -1267,9 +1267,9 @@ export function main() {
expect(form.value).toEqual({'login': 'bb'});
// custom validator
expect(form.get('login') !.errors).toEqual({'err': true});
expect(form.get('login').errors).toEqual({'err': true});
form.setValue({login: 'expected'});
expect(form.get('login') !.errors).toEqual(null);
expect(form.get('login').errors).toEqual(null);
});
it('should support non builtin input elements that fire a change event without a \'target\' property',
@ -1295,7 +1295,7 @@ export function main() {
});
fixture.detectChanges();
expect(fixture.componentInstance.form.status).toEqual('DISABLED');
expect(fixture.componentInstance.form.get('login') !.status).toEqual('DISABLED');
expect(fixture.componentInstance.form.get('login').status).toEqual('DISABLED');
});
it('should support custom accessors without setDisabledState - formControlDirective',
@ -1539,9 +1539,9 @@ export function main() {
.toEqual(pattern.nativeElement.getAttribute('pattern'));
fixture.componentInstance.required = false;
fixture.componentInstance.minLen = null !;
fixture.componentInstance.maxLen = null !;
fixture.componentInstance.pattern = null !;
fixture.componentInstance.minLen = null;
fixture.componentInstance.maxLen = null;
fixture.componentInstance.pattern = null;
fixture.detectChanges();
expect(form.hasError('required', ['login'])).toEqual(false);
@ -1581,9 +1581,9 @@ export function main() {
fixture.detectChanges();
fixture.componentInstance.required = false;
fixture.componentInstance.minLen = null !;
fixture.componentInstance.maxLen = null !;
fixture.componentInstance.pattern = null !;
fixture.componentInstance.minLen = null;
fixture.componentInstance.maxLen = null;
fixture.componentInstance.pattern = null;
fixture.detectChanges();
expect(newForm.hasError('required', ['login'])).toEqual(false);
@ -1681,7 +1681,7 @@ export function main() {
const fixture = initTest(FormControlComp);
const resultArr: number[] = [];
fixture.componentInstance.control =
new FormControl('', null !, observableValidator(resultArr));
new FormControl('', null, observableValidator(resultArr));
fixture.detectChanges();
tick(100);

View File

@ -107,9 +107,9 @@ export function main() {
tick();
const form = fixture.debugElement.children[0].injector.get(NgForm);
expect(form.control.get('name') !.value).toEqual({first: 'Nancy', last: 'Drew'});
expect(form.control.get('name.first') !.value).toEqual('Nancy');
expect(form.control.get('email') !.value).toEqual('some email');
expect(form.control.get('name').value).toEqual({first: 'Nancy', last: 'Drew'});
expect(form.control.get('name.first').value).toEqual('Nancy');
expect(form.control.get('email').value).toEqual('some email');
}));
it('should remove controls and control groups from form control model', fakeAsync(() => {
@ -121,7 +121,7 @@ export function main() {
tick();
const form = fixture.debugElement.children[0].injector.get(NgForm);
expect(form.control.get('email') !.value).toEqual('some email');
expect(form.control.get('email').value).toEqual('some email');
expect(form.value).toEqual({name: {first: 'Nancy'}, email: 'some email'});
// should remove individual control successfully
@ -132,8 +132,8 @@ export function main() {
expect(form.control.get('email')).toBe(null);
expect(form.value).toEqual({name: {first: 'Nancy'}});
expect(form.control.get('name') !.value).toEqual({first: 'Nancy'});
expect(form.control.get('name.first') !.value).toEqual('Nancy');
expect(form.control.get('name').value).toEqual({first: 'Nancy'});
expect(form.control.get('name.first').value).toEqual('Nancy');
// should remove form group successfully
fixture.componentInstance.groupShowing = false;
@ -228,7 +228,7 @@ export function main() {
it('should not create a template-driven form when ngNoForm is used', () => {
const fixture = initTest(NgNoFormComp);
fixture.detectChanges();
expect(fixture.debugElement.children[0].providerTokens !.length).toEqual(0);
expect(fixture.debugElement.children[0].providerTokens.length).toEqual(0);
});
it('should not add novalidate when ngNoForm is used', () => {
@ -282,7 +282,7 @@ export function main() {
describe('submit and reset events', () => {
it('should emit ngSubmit event with the original submit event on submit', fakeAsync(() => {
const fixture = initTest(NgModelForm);
fixture.componentInstance.event = null !;
fixture.componentInstance.event = null;
const form = fixture.debugElement.query(By.css('form'));
dispatchEvent(form.nativeElement, 'submit');
@ -355,11 +355,11 @@ export function main() {
expect(form.valid).toEqual(true);
expect(form.value).toEqual({});
let formValidity: string = undefined !;
let formValue: Object = undefined !;
let formValidity: string;
let formValue: Object;
form.statusChanges !.subscribe((status: string) => formValidity = status);
form.valueChanges !.subscribe((value: string) => formValue = value);
form.statusChanges.subscribe((status: string) => formValidity = status);
form.valueChanges.subscribe((value: string) => formValue = value);
tick();
@ -374,8 +374,8 @@ export function main() {
fixture.detectChanges();
tick();
form.get('name') !.valueChanges.subscribe(
() => { expect(form.get('name') !.dirty).toBe(true); });
form.get('name').valueChanges.subscribe(
() => { expect(form.get('name').dirty).toBe(true); });
const inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
inputEl.value = 'newValue';
@ -396,10 +396,10 @@ export function main() {
inputEl.value = 'newValue';
dispatchEvent(inputEl, 'input');
expect(form.get('name') !.pristine).toBe(false);
expect(form.get('name').pristine).toBe(false);
form.get('name') !.valueChanges.subscribe(
() => { expect(form.get('name') !.pristine).toBe(true); });
form.get('name').valueChanges.subscribe(
() => { expect(form.get('name').pristine).toBe(true); });
dispatchEvent(formEl, 'reset');
}));
@ -418,7 +418,7 @@ export function main() {
const form = fixture.debugElement.children[0].injector.get(NgForm);
expect(form.value).toEqual({name: {first: '', last: 'Drew'}, email: 'some email'});
expect(form.valid).toBe(false);
expect(form.control.get('name.first') !.disabled).toBe(false);
expect(form.control.get('name.first').disabled).toBe(false);
fixture.componentInstance.isDisabled = true;
fixture.detectChanges();
@ -426,7 +426,7 @@ export function main() {
expect(form.value).toEqual({name: {last: 'Drew'}, email: 'some email'});
expect(form.valid).toBe(true);
expect(form.control.get('name.first') !.disabled).toBe(true);
expect(form.control.get('name.first').disabled).toBe(true);
}));
it('should add disabled attribute in the UI if disable() is called programmatically',
@ -438,7 +438,7 @@ export function main() {
tick();
const form = fixture.debugElement.children[0].injector.get(NgForm);
form.control.get('name.first') !.disable();
form.control.get('name.first').disable();
fixture.detectChanges();
tick();
@ -455,7 +455,7 @@ export function main() {
fixture.detectChanges();
fixture.whenStable().then(() => {
const form = fixture.debugElement.children[0].injector.get(NgForm);
expect(form.control.get('name') !.disabled).toBe(true);
expect(form.control.get('name').disabled).toBe(true);
const customInput = fixture.debugElement.query(By.css('[name="custom"]'));
expect(customInput.nativeElement.disabled).toEqual(true);
@ -477,7 +477,7 @@ export function main() {
fixture.detectChanges();
tick();
const form = fixture.debugElement.children[0].injector.get(NgForm);
expect(form.control.get('name') !.disabled).toBe(true);
expect(form.control.get('name').disabled).toBe(true);
const input = fixture.debugElement.query(By.css('input'));
expect(input.nativeElement.disabled).toEqual(true);
@ -495,7 +495,7 @@ export function main() {
tick();
const form = fixture.debugElement.children[0].injector.get(NgForm);
form.control.get('food') !.disable();
form.control.get('food').disable();
tick();
const inputs = fixture.debugElement.queryAll(By.css('input'));
@ -620,7 +620,7 @@ export function main() {
fixture.detectChanges();
tick();
fixture.componentInstance.food = null !;
fixture.componentInstance.food = null;
fixture.detectChanges();
tick();
@ -632,7 +632,7 @@ export function main() {
fixture.detectChanges();
tick();
fixture.componentInstance.food = undefined !;
fixture.componentInstance.food = undefined;
fixture.detectChanges();
tick();
expect(inputs[0].nativeElement.checked).toEqual(false);
@ -724,7 +724,7 @@ export function main() {
const fixture = initTest(NgModelSelectWithNullForm);
const comp = fixture.componentInstance;
comp.cities = [{'name': 'SF'}, {'name': 'NYC'}];
comp.selectedCity = null !;
comp.selectedCity = null;
fixture.detectChanges();
const select = fixture.debugElement.query(By.css('select'));
@ -745,7 +745,7 @@ export function main() {
it('should throw an error when compareWith is not a function', () => {
const fixture = initTest(NgModelSelectWithCustomCompareFnForm);
const comp = fixture.componentInstance;
comp.compareFn = null !;
comp.compareFn = null;
expect(() => fixture.detectChanges())
.toThrowError(/compareWith must be a function, but received null/);
});
@ -833,7 +833,7 @@ export function main() {
it('should throw an error when compareWith is not a function', () => {
const fixture = initTest(NgModelSelectMultipleWithCustomCompareFnForm);
const comp = fixture.componentInstance;
comp.compareFn = null !;
comp.compareFn = null;
expect(() => fixture.detectChanges())
.toThrowError(/compareWith must be a function, but received null/);
});
@ -885,7 +885,7 @@ export function main() {
tick();
const control =
fixture.debugElement.children[0].injector.get(NgForm).control.get('checkbox') !;
fixture.debugElement.children[0].injector.get(NgForm).control.get('checkbox');
const input = fixture.debugElement.query(By.css('input'));
expect(input.nativeElement.checked).toBe(false);
@ -921,7 +921,7 @@ export function main() {
tick();
const control =
fixture.debugElement.children[0].injector.get(NgForm).control.get('email') !;
fixture.debugElement.children[0].injector.get(NgForm).control.get('email');
const input = fixture.debugElement.query(By.css('input'));
expect(control.hasError('email')).toBe(false);
@ -1114,9 +1114,9 @@ export function main() {
.toEqual(pattern.nativeElement.getAttribute('pattern'));
fixture.componentInstance.required = false;
fixture.componentInstance.minLen = null !;
fixture.componentInstance.maxLen = null !;
fixture.componentInstance.pattern = null !;
fixture.componentInstance.minLen = null;
fixture.componentInstance.maxLen = null;
fixture.componentInstance.pattern = null;
fixture.detectChanges();
expect(form.control.hasError('required', ['required'])).toEqual(false);

View File

@ -179,33 +179,33 @@ export function main() {
});
it('should not error on "null" pattern',
() => expect(Validators.pattern(null !)(new FormControl('aaAA'))).toBeNull());
() => expect(Validators.pattern(null)(new FormControl('aaAA'))).toBeNull());
it('should not error on "undefined" pattern',
() => expect(Validators.pattern(undefined !)(new FormControl('aaAA'))).toBeNull());
() => expect(Validators.pattern(undefined)(new FormControl('aaAA'))).toBeNull());
});
describe('compose', () => {
it('should return null when given null',
() => { expect(Validators.compose(null !)).toBe(null); });
() => { expect(Validators.compose(null)).toBe(null); });
it('should collect errors from all the validators', () => {
const c = Validators.compose([validator('a', true), validator('b', true)]) !;
const c = Validators.compose([validator('a', true), validator('b', true)]);
expect(c(new FormControl(''))).toEqual({'a': true, 'b': true});
});
it('should run validators left to right', () => {
const c = Validators.compose([validator('a', 1), validator('a', 2)]) !;
const c = Validators.compose([validator('a', 1), validator('a', 2)]);
expect(c(new FormControl(''))).toEqual({'a': 2});
});
it('should return null when no errors', () => {
const c = Validators.compose([Validators.nullValidator, Validators.nullValidator]) !;
const c = Validators.compose([Validators.nullValidator, Validators.nullValidator]);
expect(c(new FormControl(''))).toBeNull();
});
it('should ignore nulls', () => {
const c = Validators.compose([null !, Validators.required]) !;
const c = Validators.compose([null, Validators.required]);
expect(c(new FormControl(''))).toEqual({'required': true});
});
});
@ -221,13 +221,13 @@ export function main() {
}
it('should return null when given null',
() => { expect(Validators.composeAsync(null !)).toBeNull(); });
() => { expect(Validators.composeAsync(null)).toBeNull(); });
it('should collect errors from all the validators', fakeAsync(() => {
const v = Validators.composeAsync(
[promiseValidator({'one': true}), promiseValidator({'two': true})]) !;
[promiseValidator({'one': true}), promiseValidator({'two': true})]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
tick();
@ -236,10 +236,10 @@ export function main() {
}));
it('should normalize and evaluate async validator-directives correctly', fakeAsync(() => {
const v = Validators.composeAsync([normalizeAsyncValidator(
new AsyncValidatorDirective('expected', {'one': true}))]) !;
const v = Validators.composeAsync(
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
tick();
@ -248,9 +248,9 @@ export function main() {
}));
it('should return null when no errors', fakeAsync(() => {
const v = Validators.composeAsync([promiseValidator({'one': true})]) !;
const v = Validators.composeAsync([promiseValidator({'one': true})]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('expected')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
tick();
@ -259,9 +259,9 @@ export function main() {
}));
it('should ignore nulls', fakeAsync(() => {
const v = Validators.composeAsync([promiseValidator({'one': true}), null !]) !;
const v = Validators.composeAsync([promiseValidator({'one': true}), null]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
tick();
@ -279,13 +279,13 @@ export function main() {
}
it('should return null when given null',
() => { expect(Validators.composeAsync(null !)).toBeNull(); });
() => { expect(Validators.composeAsync(null)).toBeNull(); });
it('should collect errors from all the validators', () => {
const v = Validators.composeAsync(
[observableValidator({'one': true}), observableValidator({'two': true})]) !;
[observableValidator({'one': true}), observableValidator({'two': true})]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
@ -294,19 +294,19 @@ export function main() {
it('should normalize and evaluate async validator-directives correctly', () => {
const v = Validators.composeAsync(
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]) !;
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors) !;
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
expect(errorMap).toEqual({'one': true});
});
it('should return null when no errors', () => {
const v = Validators.composeAsync([observableValidator({'one': true})]) !;
const v = Validators.composeAsync([observableValidator({'one': true})]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('expected')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
@ -314,9 +314,9 @@ export function main() {
});
it('should ignore nulls', () => {
const v = Validators.composeAsync([observableValidator({'one': true}), null !]) !;
const v = Validators.composeAsync([observableValidator({'one': true}), null]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
@ -329,9 +329,9 @@ export function main() {
}
const v = Validators.composeAsync(
[getTimerObs(100, {one: true}), getTimerObs(200, {two: true})]) !;
[getTimerObs(100, {one: true}), getTimerObs(200, {two: true})]);
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any};
first.call(v(new FormControl('invalid')))
.subscribe((errors: {[key: string]: any}) => errorMap = errors);