refactor(): use const and let instead of var
This commit is contained in:

committed by
Victor Berchet

parent
73593d4bf3
commit
77ee27c59e
@ -29,9 +29,9 @@ class CustomValidatorDirective implements Validator {
|
||||
|
||||
function asyncValidator(expected: any /** TODO #9100 */, timeout = 0) {
|
||||
return (c: any /** TODO #9100 */) => {
|
||||
var resolve: (result: any) => void;
|
||||
var promise = new Promise(res => { resolve = res; });
|
||||
var res = c.value != expected ? {'async': true} : null;
|
||||
let resolve: (result: any) => void;
|
||||
const promise = new Promise(res => { resolve = res; });
|
||||
const res = c.value != expected ? {'async': true} : null;
|
||||
if (timeout == 0) {
|
||||
resolve(res);
|
||||
} else {
|
||||
@ -43,13 +43,13 @@ function asyncValidator(expected: any /** TODO #9100 */, timeout = 0) {
|
||||
|
||||
export function main() {
|
||||
describe('Form Directives', () => {
|
||||
var defaultAccessor: DefaultValueAccessor;
|
||||
let defaultAccessor: DefaultValueAccessor;
|
||||
|
||||
beforeEach(() => { defaultAccessor = new DefaultValueAccessor(null, null); });
|
||||
|
||||
describe('shared', () => {
|
||||
describe('selectValueAccessor', () => {
|
||||
var dir: NgControl;
|
||||
let dir: NgControl;
|
||||
|
||||
beforeEach(() => { dir = <any>new SpyNgControl(); });
|
||||
|
||||
@ -60,14 +60,14 @@ export function main() {
|
||||
() => { expect(selectValueAccessor(dir, [defaultAccessor])).toEqual(defaultAccessor); });
|
||||
|
||||
it('should return checkbox accessor when provided', () => {
|
||||
var 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', () => {
|
||||
var selectAccessor = new SelectControlValueAccessor(null, null);
|
||||
const selectAccessor = new SelectControlValueAccessor(null, null);
|
||||
expect(selectValueAccessor(dir, [
|
||||
defaultAccessor, selectAccessor
|
||||
])).toEqual(selectAccessor);
|
||||
@ -81,14 +81,14 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should throw when more than one build-in accessor is provided', () => {
|
||||
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
|
||||
var 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', () => {
|
||||
var customAccessor = new SpyValueAccessor();
|
||||
var checkboxAccessor = new CheckboxControlValueAccessor(null, null);
|
||||
const customAccessor = new SpyValueAccessor();
|
||||
const checkboxAccessor = new CheckboxControlValueAccessor(null, null);
|
||||
expect(selectValueAccessor(dir, <any>[defaultAccessor, customAccessor, checkboxAccessor]))
|
||||
.toEqual(customAccessor);
|
||||
});
|
||||
@ -102,22 +102,22 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should throw when more than one custom accessor is provided', () => {
|
||||
var customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
|
||||
const customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
|
||||
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('composeValidators', () => {
|
||||
it('should compose functions', () => {
|
||||
var dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
|
||||
var dummy2 = (_: any /** TODO #9100 */) => ({'dummy2': true});
|
||||
var v = composeValidators([dummy1, dummy2]);
|
||||
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
|
||||
const dummy2 = (_: any /** TODO #9100 */) => ({'dummy2': true});
|
||||
const v = composeValidators([dummy1, dummy2]);
|
||||
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'dummy2': true});
|
||||
});
|
||||
|
||||
it('should compose validator directives', () => {
|
||||
var dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
|
||||
var v = composeValidators([dummy1, new CustomValidatorDirective()]);
|
||||
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
|
||||
const v = composeValidators([dummy1, new CustomValidatorDirective()]);
|
||||
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'custom': true});
|
||||
});
|
||||
});
|
||||
@ -228,7 +228,7 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('addFormGroup', () => {
|
||||
var matchingPasswordsValidator = (g: any /** TODO #9100 */) => {
|
||||
const matchingPasswordsValidator = (g: any /** TODO #9100 */) => {
|
||||
if (g.controls['password'].value != g.controls['passwordConfirm'].value) {
|
||||
return {'differentPasswords': true};
|
||||
} else {
|
||||
@ -237,7 +237,7 @@ export function main() {
|
||||
};
|
||||
|
||||
it('should set up validator', fakeAsync(() => {
|
||||
var group = new FormGroupName(
|
||||
const group = new FormGroupName(
|
||||
form, [matchingPasswordsValidator], [asyncValidator('expected')]);
|
||||
group.name = 'passwords';
|
||||
form.addFormGroup(group);
|
||||
@ -283,8 +283,8 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should set up a sync validator', () => {
|
||||
var formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
|
||||
var f = new FormGroupDirective([formValidator], []);
|
||||
const formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
|
||||
const f = new FormGroupDirective([formValidator], []);
|
||||
f.form = formModel;
|
||||
f.ngOnChanges({'form': new SimpleChange(null, null)});
|
||||
|
||||
@ -292,7 +292,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should set up an async validator', fakeAsync(() => {
|
||||
var f = new FormGroupDirective([], [asyncValidator('expected')]);
|
||||
const f = new FormGroupDirective([], [asyncValidator('expected')]);
|
||||
f.form = formModel;
|
||||
f.ngOnChanges({'form': new SimpleChange(null, null)});
|
||||
|
||||
@ -304,10 +304,10 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('NgForm', () => {
|
||||
var form: any /** TODO #9100 */;
|
||||
var formModel: FormGroup;
|
||||
var loginControlDir: any /** TODO #9100 */;
|
||||
var personControlGroupDir: any /** TODO #9100 */;
|
||||
let form: any /** TODO #9100 */;
|
||||
let formModel: FormGroup;
|
||||
let loginControlDir: any /** TODO #9100 */;
|
||||
let personControlGroupDir: any /** TODO #9100 */;
|
||||
|
||||
beforeEach(() => {
|
||||
form = new NgForm([], []);
|
||||
@ -378,8 +378,8 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should set up sync validator', fakeAsync(() => {
|
||||
var formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
|
||||
var f = new NgForm([formValidator], []);
|
||||
const formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
|
||||
const f = new NgForm([formValidator], []);
|
||||
|
||||
tick();
|
||||
|
||||
@ -387,7 +387,7 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should set up async validator', fakeAsync(() => {
|
||||
var f = new NgForm([], [asyncValidator('expected')]);
|
||||
const f = new NgForm([], [asyncValidator('expected')]);
|
||||
|
||||
tick();
|
||||
|
||||
@ -396,13 +396,13 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('FormGroupName', () => {
|
||||
var formModel: any /** TODO #9100 */;
|
||||
var controlGroupDir: any /** TODO #9100 */;
|
||||
let formModel: any /** TODO #9100 */;
|
||||
let controlGroupDir: any /** TODO #9100 */;
|
||||
|
||||
beforeEach(() => {
|
||||
formModel = new FormGroup({'login': new FormControl(null)});
|
||||
|
||||
var parent = new FormGroupDirective([], []);
|
||||
const parent = new FormGroupDirective([], []);
|
||||
parent.form = new FormGroup({'group': formModel});
|
||||
controlGroupDir = new FormGroupName(parent, [], []);
|
||||
controlGroupDir.name = 'group';
|
||||
@ -436,8 +436,8 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('FormArrayName', () => {
|
||||
var formModel: FormArray;
|
||||
var formArrayDir: FormArrayName;
|
||||
let formModel: FormArray;
|
||||
let formArrayDir: FormArrayName;
|
||||
|
||||
beforeEach(() => {
|
||||
const parent = new FormGroupDirective([], []);
|
||||
@ -473,9 +473,9 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('FormControlDirective', () => {
|
||||
var controlDir: any /** TODO #9100 */;
|
||||
var control: any /** TODO #9100 */;
|
||||
var checkProperties = function(control: any /** TODO #9100 */) {
|
||||
let controlDir: any /** TODO #9100 */;
|
||||
let control: any /** TODO #9100 */;
|
||||
const checkProperties = function(control: any /** TODO #9100 */) {
|
||||
expect(controlDir.control).toBe(control);
|
||||
expect(controlDir.value).toBe(control.value);
|
||||
expect(controlDir.valid).toBe(control.valid);
|
||||
@ -512,7 +512,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should reexport new control properties', () => {
|
||||
var newControl = new FormControl(null);
|
||||
const newControl = new FormControl(null);
|
||||
controlDir.form = newControl;
|
||||
controlDir.ngOnChanges({'form': new SimpleChange(control, newControl)});
|
||||
|
||||
@ -636,13 +636,13 @@ export function main() {
|
||||
});
|
||||
|
||||
describe('FormControlName', () => {
|
||||
var formModel: any /** TODO #9100 */;
|
||||
var controlNameDir: any /** TODO #9100 */;
|
||||
let formModel: any /** TODO #9100 */;
|
||||
let controlNameDir: any /** TODO #9100 */;
|
||||
|
||||
beforeEach(() => {
|
||||
formModel = new FormControl('name');
|
||||
|
||||
var parent = new FormGroupDirective([], []);
|
||||
const parent = new FormGroupDirective([], []);
|
||||
parent.form = new FormGroup({'name': formModel});
|
||||
controlNameDir = new FormControlName(parent, [], [], [defaultAccessor]);
|
||||
controlNameDir.name = 'name';
|
||||
|
Reference in New Issue
Block a user