UNPKG

2.58 kBJavaScriptView Raw
1if (typeof require !== 'undefined') {
2 var Validator = require('../src/validator.js');
3 var expect = require('chai').expect;
4} else {
5 var Validator = window.Validator;
6 var expect = window.chai.expect;
7}
8
9describe('min validation rule', function() {
10 it('should fail with the name "D". Minimum size is 2 letters.', function() {
11 var validator = new Validator({
12 name: 'D'
13 }, {
14 name: 'min:2'
15 });
16 expect(validator.passes()).to.be.false;
17 });
18
19 it('should pass with the name "Da". Minimum is 2 letters.', function() {
20 var validator = new Validator({
21 name: 'Da'
22 }, {
23 name: 'min:2'
24 });
25 expect(validator.passes()).to.be.true;
26 });
27
28 it('should pass with the age "18". Minimum is 18.', function() {
29 var validator = new Validator({
30 age: 18
31 }, {
32 age: 'min:18'
33 });
34 expect(validator.passes()).to.be.true;
35 });
36
37 it('should fail with the age "17". Minimum is 18.', function() {
38 var validator = new Validator({
39 age: 17
40 }, {
41 age: 'min:18'
42 });
43 expect(validator.fails()).to.be.true;
44 });
45
46 it('should fail with value of 0.04', function() {
47 var validator = new Validator({
48 val: 0.04
49 }, {
50 val: 'min:0.05'
51 });
52 expect(validator.fails()).to.be.true;
53 });
54
55 it('should fail with boolean true value', function() {
56 var validator = new Validator({
57 val: true
58 }, {
59 val: 'min:0.05'
60 });
61 expect(validator.fails()).to.be.true;
62 });
63
64 it('should fail with boolean false value', function() {
65 var validator = new Validator({
66 val: false
67 }, {
68 val: 'min:0.05'
69 });
70 expect(validator.fails()).to.be.true;
71 });
72
73 it('should pass with an undefined value', function() {
74 var validator = new Validator({}, {
75 val: 'min:0.05'
76 });
77 expect(validator.fails()).to.be.false;
78 expect(validator.passes()).to.be.true;
79 });
80
81 it('should pass with an empty string value', function() {
82 var validator = new Validator({
83 val: ''
84 }, {
85 val: 'min:0.05'
86 });
87 expect(validator.fails()).to.be.false;
88 expect(validator.passes()).to.be.true;
89 });
90
91 it('should pass when given string-integer value', function() {
92 var validator = new Validator({
93 val: '18'
94 }, {
95 val: 'integer|min:16'
96 });
97 expect(validator.passes()).to.be.true;
98 });
99
100 it('should pass when given string-float value', function() {
101 var validator = new Validator({
102 val: '17.56'
103 }, {
104 val: 'numeric|min:17.5'
105 });
106 expect(validator.passes()).to.be.true;
107 });
108});