UNPKG

vue-forms-builder

Version:

Typescript forms builder package written specifically for Vue

52 lines 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Validators_1 = require("../Validators"); var FormControl_1 = require("./../FormControl"); var FormGroup_1 = require("./../FormGroup"); describe('FormGroup class', function () { describe('initialize the FormGroup instance', function () { var formGroup = new FormGroup_1.FormGroup({ name: new FormControl_1.FormControl(null, Validators_1.Validators.required) }); var formGroupNoValidators = new FormGroup_1.FormGroup({ name: new FormControl_1.FormControl(null) }); it('should created FormGroup class', function () { expect(formGroup).toBeTruthy(); expect(formGroup).toBeInstanceOf(FormGroup_1.FormGroup); }); it('group should be invalid if any control has validator', function () { expect(formGroup.valid).toBeFalsy(); }); it('group should be valid if no validators', function () { expect(formGroupNoValidators.valid).toBeTruthy(); }); it('group should have specific FormControl', function () { expect(formGroup.contains('name')).toBeTruthy(); expect(formGroup.contains('phone')).toBeFalsy(); }); it('should return a specific FormControl when get by control name', function () { expect(formGroup.get('name')).toBeInstanceOf(FormControl_1.FormControl); expect(formGroup.get('phone')).toBe(undefined); }); it('control shoud be touched when call markAllAsTouched()', function () { formGroup.markAllAsTouched(); expect(formGroup.get('name').touched).toBeTruthy(); }); it('control should have a new value when call patchValue()', function () { formGroup.patchValue({ name: 'new value', }); expect(formGroup.get('name').value).toBe('new value'); }); it('control shoud have default value when reset all', function () { formGroup.reset(); expect(formGroup.get('name').value).toBe(null); }); it('should have new control when call addControl', function () { formGroup.addControl('test', new FormControl_1.FormControl(null)); expect(formGroup.contains('test')).toBeTruthy(); }); it('should not have control when call removeControl', function () { formGroup.removeControl('test'); expect(formGroup.contains('test')).toBeFalsy(); }); }); }); //# sourceMappingURL=FormGroup.test.js.map