UNPKG

753 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('string validation rule', function() {
10 it('should pass when the input is a string', function() {
11 var validator = new Validator({
12 name: 'David'
13 }, {
14 name: 'string'
15 });
16
17 expect(validator.passes()).to.be.true;
18 });
19
20 it('should fail when the input is not a string', function() {
21 var validator = new Validator({
22 name: 5
23 }, {
24 name: 'string'
25 });
26
27 expect(validator.passes()).to.be.false;
28 expect(validator.errors.first('name')).to.equal('The name must be a string.');
29 });
30});