UNPKG

2.15 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('numeric validation rule', function() {
10 it('should pass with a numeric value', function() {
11 var validator = new Validator({
12 age: 44
13 }, {
14 age: 'numeric'
15 });
16 expect(validator.passes()).to.be.true;
17 });
18
19 it('should pass with a decimal numeric value', function() {
20 var validator = new Validator({
21 measurement: 0.5454
22 }, {
23 measurement: 'numeric'
24 });
25 expect(validator.passes()).to.be.true;
26 });
27
28 it('should pass with a string numeric value', function() {
29 var validator = new Validator({
30 age: '44'
31 }, {
32 age: 'numeric'
33 });
34 expect(validator.passes()).to.be.true;
35 });
36
37 it('should pass with a string decimal numeric value', function() {
38 var validator = new Validator({
39 measurement: '0.5454'
40 }, {
41 measurement: 'numeric'
42 });
43 expect(validator.passes()).to.be.true;
44 });
45
46 it('should fail with a string value', function() {
47 var validator = new Validator({
48 age: '18something'
49 }, {
50 age: 'numeric'
51 });
52 expect(validator.fails()).to.be.true;
53 });
54
55 it('should fail with a boolean true value', function() {
56 var validator = new Validator({
57 age: true
58 }, {
59 age: 'numeric'
60 });
61 expect(validator.fails()).to.be.true;
62 });
63
64 it('should fail with a boolean false value', function() {
65 var validator = new Validator({
66 age: false
67 }, {
68 age: 'numeric'
69 });
70 expect(validator.fails()).to.be.true;
71 });
72
73 it('should pass with no value', function() {
74 var validator = new Validator({}, {
75 age: 'numeric'
76 });
77 expect(validator.passes()).to.be.true;
78 expect(validator.fails()).to.be.false;
79 });
80
81 it('should pass with an empty string value', function() {
82 var validator = new Validator({
83 age: ''
84 }, {
85 age: 'numeric'
86 });
87 expect(validator.passes()).to.be.true;
88 expect(validator.fails()).to.be.false;
89 });
90});