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('alternative initialization using an array instead pipe', function() {
|
10 | beforeEach(function() {
|
11 | validator = new Validator({
|
12 | name: 'David',
|
13 | email: 'johndoe@gmail.com',
|
14 | salary: '10,000.00',
|
15 | birthday: '03/07/1980',
|
16 | nick: 'Dav'
|
17 | }, {
|
18 | name: ['required', 'min:3', 'max:10'],
|
19 | email: ['required', 'email'],
|
20 | salary: ['required', 'regex:/^\\$?(?!0.00)(([0-9]{1,3},([0-9]{3},)*)[0-9]{3}|[0-9]{1,3})(\\.[0-9]{2})?$/'],
|
21 | birthday: ['required', 'regex:/^([1-9]|0[1-9]|[12][0-9]|3[01])\\D([1-9]|0[1-9]|1[012])\\D(19[0-9][0-9]|20[0-9][0-9])$/'],
|
22 | nick: ['required', 'regex:/^X/']
|
23 | });
|
24 | });
|
25 |
|
26 | it('should fail 1 validation rule', function() {
|
27 | expect(validator.passes()).to.be.false;
|
28 | expect(validator.fails()).to.be.true;
|
29 | expect(validator.errors.first('nick')).to.equal('The nick format is invalid.');
|
30 | });
|
31 | });
|