UNPKG

1.94 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('size validation rule', function() {
10 it('should fail with the state = C. Size must be 2 letters.', function() {
11 var validator = new Validator({
12 state: 'C'
13 }, {
14 state: 'size:2'
15 });
16 expect(validator.fails()).to.be.true;
17 });
18
19 it('should pass with the state = CA. Size must be 2 letters.', function() {
20 var validator = new Validator({
21 state: 'CA'
22 }, {
23 state: 'size:2'
24 });
25 expect(validator.passes()).to.be.true;
26 });
27
28 it('should pass with an empty string', function() {
29 var validator = new Validator({
30 state: ''
31 }, {
32 state: 'size:2'
33 });
34 expect(validator.passes()).to.be.true;
35 });
36
37 it('should pass with the age 65. Size must be 65', function() {
38 var validator = new Validator({
39 age: 65
40 }, {
41 age: 'size:65'
42 });
43 expect(validator.passes()).to.be.true;
44 });
45
46 it('should fail with the age 64. Size must be 65.', function() {
47 var validator = new Validator({
48 age: 64
49 }, {
50 age: 'size:65'
51 });
52 expect(validator.fails()).to.be.true;
53 });
54
55 it('should pass when no value exists in the input object', function() {
56 var validator = new Validator({}, {
57 age: 'size:65'
58 });
59 expect(validator.fails()).to.be.false;
60 expect(validator.passes()).to.be.true;
61 });
62
63 it('should pass with string-integer', function() {
64 var validator = new Validator({
65 age: '65'
66 }, {
67 age: 'integer|size:65'
68 });
69 expect(validator.passes()).to.be.true;
70 });
71
72 it('should pass with float-integer', function() {
73 var validator = new Validator({
74 age: '65.36'
75 }, {
76 age: 'numeric|size:65.36'
77 });
78 expect(validator.passes()).to.be.true;
79 });
80});