vue-forms-builder
Version:
Typescript forms builder package written specifically for Vue
71 lines • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("../index");
var PHONE_PATTERN = new RegExp('^[0-9]{9,12}$');
describe('Validators class', function () {
it('should created Validator class', function () {
expect(new index_1.Validators()).toBeTruthy();
});
describe('required validator', function () {
it('should return null if value is non-empty', function () {
expect(index_1.Validators.required('test')).toBe(null);
});
it('should return validation error if value is empty', function () {
expect(index_1.Validators.required('')).toStrictEqual({ required: true });
});
});
describe('requiredTrue validator', function () {
it('should return null if value is true', function () {
expect(index_1.Validators.requiredTrue(true)).toBe(null);
});
it('should return validation error if value is false', function () {
expect(index_1.Validators.requiredTrue(false)).toStrictEqual({ required: true });
});
});
describe('pattern validator', function () {
var pattern = index_1.Validators.pattern(PHONE_PATTERN);
it('should return null if value match a pattern', function () {
expect(pattern('876679328')).toBe(null);
});
it('should return validation error if value not match a pattern', function () {
expect(pattern('test1234')).toStrictEqual({ pattern: true });
});
});
describe('min validator', function () {
var min = index_1.Validators.min(3);
it('should return null if value is greater than or equal to the provided number', function () {
expect(min(5)).toBe(null);
});
it('should return validation error if value is less than provided number', function () {
expect(min(1)).toStrictEqual({ min: true });
});
});
describe('max validator', function () {
var max = index_1.Validators.max(3);
it('should return null if value is less than or equal to the provided number', function () {
expect(max(1)).toBe(null);
});
it('should return validation error if value is greater than provided number', function () {
expect(max(5)).toStrictEqual({ max: true });
});
});
describe('minLength validator', function () {
var minLength = index_1.Validators.minLength(3);
it('should return null if value length is greater than or equal to the provided minimum length', function () {
expect(minLength('test')).toBe(null);
});
it('should return validation error if value length is less than provided minimum length', function () {
expect(minLength('t')).toStrictEqual({ minLength: true });
});
});
describe('maxLength validator', function () {
var maxLength = index_1.Validators.maxLength(3);
it('should return null if value length is less than or equal to the provided minimum length', function () {
expect(maxLength('t')).toBe(null);
});
it('should return validation error if value length is greater than provided minimum length', function () {
expect(maxLength('test')).toStrictEqual({ maxLength: true });
});
});
});
//# sourceMappingURL=Validators.test.js.map