vue-forms-builder
Version:
Typescript forms builder package written specifically for Vue
58 lines • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var Validators_1 = require("./../Validators");
var FormControl_1 = require("./../FormControl");
describe('FormControl class', function () {
describe('initialize the FormControl instance', function () {
var control = new FormControl_1.FormControl('test', Validators_1.Validators.minLength(5));
var controlNoValidator = new FormControl_1.FormControl(true);
it('should created FormControl class', function () {
expect(control).toBeTruthy();
expect(control).toBeInstanceOf(FormControl_1.FormControl);
});
it('should be untouched on initialization', function () {
expect(control.touched).toBeFalsy();
});
it('value should be equal to the specified value', function () {
expect(control.value).toBe('test');
});
it('should have specific validator', function () {
expect(control.hasValidator(Validators_1.Validators.minLength(5))).toBeTruthy();
expect(control.hasValidator(Validators_1.Validators.requiredTrue)).toBeFalsy();
});
it('should be invalid if has validators', function () {
expect(control.valid).toBeFalsy();
});
it('should be valid if no validators', function () {
expect(controlNoValidator.valid).toBeTruthy();
});
it('should has error if has validators and the value does not meet the requirements', function () {
expect(control.error).toMatchObject({ minLength: true });
expect(control.error).not.toMatchObject({ pattern: true });
});
it('should be touched when set value', function () {
control.setValue('new value to set');
expect(control.touched).toBeTruthy();
});
it('should has error when set or add new validator and the value does not meet the requirements', function () {
control.setValidators(Validators_1.Validators.maxLength(10));
expect(control.error).toMatchObject({ maxLength: true });
control.setValue(1);
control.addValidators(Validators_1.Validators.min(5));
expect(control.error).toMatchObject({ min: true });
});
it('hasError() should return true when control has specific error, if not should return false', function () {
expect(control.hasError('min')).toBeTruthy();
expect(control.hasError('maxLength')).toBeFalsy();
});
it('should be valid if clear validators', function () {
control.clearValidators();
expect(control.valid).toBeTruthy();
});
it('should have default value when reset', function () {
control.reset();
expect(control.value).toBe('test');
});
});
});
//# sourceMappingURL=FormControl.test.js.map