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('alpha_dash validation rule', function() {
|
10 | it('should fail with non alpha dash characters', function() {
|
11 | var validator = new Validator({
|
12 | name: 'David *'
|
13 | }, {
|
14 | name: 'alpha_dash'
|
15 | });
|
16 | expect(validator.passes()).to.be.false;
|
17 | expect(validator.fails()).to.be.true;
|
18 | });
|
19 |
|
20 | it('should fail with non-alphabetic characters', function() {
|
21 | var validator = new Validator({
|
22 | name: 12
|
23 | }, {
|
24 | name: 'alpha_dash'
|
25 | });
|
26 | expect(validator.fails()).to.be.false;
|
27 | expect(validator.passes()).to.be.true;
|
28 | });
|
29 |
|
30 | it('should pass with only alpha dash characters', function() {
|
31 | var validator = new Validator({
|
32 | name: 'David9_-'
|
33 | }, {
|
34 | name: 'alpha_dash'
|
35 | });
|
36 | expect(validator.passes()).to.be.true;
|
37 | expect(validator.fails()).to.be.false;
|
38 | });
|
39 |
|
40 | it('should pass when the field is blank / optional', function() {
|
41 | var validator = new Validator({
|
42 | name: ''
|
43 | }, {
|
44 | name: 'alpha_dash'
|
45 | });
|
46 | expect(validator.passes()).to.be.true;
|
47 | });
|
48 |
|
49 | it('should pass when the field does not exist', function() {
|
50 | var validator = new Validator({}, {
|
51 | name: 'alpha_dash'
|
52 | });
|
53 | expect(validator.passes()).to.be.true;
|
54 | expect(validator.fails()).to.be.false;
|
55 | });
|
56 | });
|