1 | if (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 |
|
9 | describe('hex validation rule', function() {
|
10 | it('should fail with incorrect hexadecimal values', function() {
|
11 | var validator = new Validator({
|
12 | color: '4d4b8z',
|
13 | }, {
|
14 | color: 'hex',
|
15 | });
|
16 |
|
17 | expect(validator.fails()).to.be.true;
|
18 | expect(validator.passes()).to.be.false;
|
19 | });
|
20 |
|
21 | it('should pass for valid hexadecimal values ', function() {
|
22 | var validator = new Validator({
|
23 | mongoId: '54759eb3c090d83494e2d804',
|
24 | symbolStr: '0',
|
25 | symbolNum: 0,
|
26 | str: 'a'
|
27 | }, {
|
28 | color: 'hex',
|
29 | mongoId: 'hex',
|
30 | symbolStr: 'hex',
|
31 | symbolNum: 'hex',
|
32 | str: 'hex'
|
33 | });
|
34 |
|
35 | expect(validator.fails()).to.be.false;
|
36 | expect(validator.passes()).to.be.true;
|
37 | });
|
38 |
|
39 | it('should pass with an empty value', function() {
|
40 | var validator = new Validator({
|
41 | color: '',
|
42 | mongoId: ''
|
43 | }, {
|
44 | color: 'hex',
|
45 | mongoId: 'hex'
|
46 | });
|
47 |
|
48 | expect(validator.fails()).to.be.false;
|
49 | expect(validator.passes()).to.be.true;
|
50 | });
|
51 |
|
52 | it('should pass with an undefined value', function() {
|
53 | var validator = new Validator({}, {
|
54 | color: 'hex',
|
55 | mongoId: 'hex'
|
56 | });
|
57 |
|
58 | expect(validator.fails()).to.be.false;
|
59 | expect(validator.passes()).to.be.true;
|
60 | });
|
61 | });
|