vue-forms-builder
Version:
Typescript forms builder package written specifically for Vue
71 lines • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var FormGroup_1 = require("./../FormGroup");
var FormControl_1 = require("./../FormControl");
var FormArray_1 = require("./../FormArray");
var Validators_1 = require("../Validators");
describe('FormArray class', function () {
describe('initialize the FormArray instance', function () {
var formArray = new FormArray_1.FormArray([
new FormControl_1.FormControl(null, Validators_1.Validators.required),
new FormGroup_1.FormGroup({
name: new FormControl_1.FormControl('Test'),
}),
]);
var formArrayNoValidators = new FormArray_1.FormArray([new FormControl_1.FormControl(null)]);
it('should created FormArray class', function () {
expect(formArray).toBeTruthy();
expect(formArray).toBeInstanceOf(FormArray_1.FormArray);
});
it('array should be invalid if any control has validator', function () {
expect(formArray.valid).toBeFalsy();
});
it('array should be valid if no validators', function () {
expect(formArrayNoValidators.valid).toBeTruthy();
});
it('array should have length number 2', function () {
expect(formArray.length).toBe(2);
});
it('should return a specific control by the given index', function () {
var control = new FormControl_1.FormControl(null, Validators_1.Validators.required);
expect(formArray.at(0)).toBeInstanceOf(FormControl_1.FormControl);
expect(formArray.at(0)).toStrictEqual(control);
});
it('array should have length number 3 when push new control', function () {
formArray.push(new FormControl_1.FormControl(null, Validators_1.Validators.required));
expect(formArray.length).toBe(3);
});
it('array should have length number 2 when remove control', function () {
formArray.removeAt(2);
expect(formArray.length).toBe(2);
});
it('array should have a new control at the given index', function () {
var control = new FormControl_1.FormControl('test');
formArray.insert(1, control);
expect(formArray.controls[1]).toStrictEqual(control);
});
it('control should be equal to the new one when called setControl() at the specific index', function () {
var control = new FormControl_1.FormControl('replace');
formArray.setControl(1, control);
expect(formArray.controls[1]).toStrictEqual(control);
});
it('control shoud be touched when call markAllAsTouched()', function () {
formArray.markAllAsTouched();
expect(formArray.controls[0].touched).toBeTruthy();
});
it('control should have a new value when call patchValue()', function () {
formArray.patchValue(['new value']);
expect(formArray.controls[0].value).toBe('new value');
});
it('control shoud have default value when reset all', function () {
formArray.reset();
expect(formArray.controls[0].value).toBe(null);
});
it('array should be empty when clear', function () {
formArray.clear();
expect(formArray.controls).toStrictEqual([]);
expect(formArray.length).toBe(0);
});
});
});
//# sourceMappingURL=FormArray.test.js.map