UNPKG

851 BJavaScriptView 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('digits rule', function() {
10 it('should be numeric and must have an exact length of 5', function() {
11 var validation = new Validator({
12 zip: '90989'
13 }, {
14 zip: 'digits:5'
15 });
16
17 expect(validation.passes()).to.be.true;
18 expect(validation.fails()).to.be.false;
19 });
20
21 it('should not pass if non-digits are present', function() {
22 var validation = new Validator({
23 zip: '9098a'
24 }, {
25 zip: 'digits:5'
26 });
27
28 expect(validation.fails()).to.be.true;
29 expect(validation.errors.first('zip')).to.equal('The zip must be 5 digits.');
30 expect(validation.passes()).to.be.false;
31 });
32});