fix(forms): Update types for TypeScript nullability support
This reverts commit 6d930d2fc5
.
This commit is contained in:

committed by
Tobias Bosch

parent
bc431888f3
commit
57bc245cb4
@ -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;
|
||||
let resolve: (result: any) => void = undefined !;
|
||||
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([]);
|
||||
});
|
||||
|
Reference in New Issue
Block a user