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('Validator constructor', function() {
|
10 | var validator;
|
11 |
|
12 | beforeEach(function() {
|
13 | validator = new Validator({
|
14 | name: 'David',
|
15 | email: 'johndoe@gmail.com'
|
16 | }, {
|
17 | name: 'required',
|
18 | email: 'required'
|
19 | }, {
|
20 | required: "You're missing :required"
|
21 | });
|
22 | });
|
23 |
|
24 | it('should expose on window if browser', function() {
|
25 | if (typeof window !== 'undefined') {
|
26 | expect(window.Validator).to.not.be.undefined;
|
27 | }
|
28 | });
|
29 |
|
30 | it('should have a rules property containing all the validation rules', function() {
|
31 | expect(validator.rules).to.be.a('object');
|
32 | });
|
33 |
|
34 | it('should have an input property containing the input data to be validated', function() {
|
35 | expect(validator.input).to.be.a('object');
|
36 | });
|
37 |
|
38 | it('should have a messages property containing the combined messages for validation', function() {
|
39 | expect(validator.messages).to.be.a('object');
|
40 | });
|
41 |
|
42 | it('should have a passes() method', function() {
|
43 | expect(validator.passes).to.be.a.function;
|
44 | });
|
45 |
|
46 | it('should have a fails() method', function() {
|
47 | expect(validator.fails).to.be.a.function;
|
48 | });
|
49 |
|
50 | it('should have a check method', function() {
|
51 | expect(validator.check).to.be.a.function;
|
52 | });
|
53 |
|
54 | it('should handle undefined data', function() {
|
55 | var validator = new Validator(undefined, { name: 'required' });
|
56 | validator.fails();
|
57 | });
|
58 |
|
59 | it('should handle null data', function() {
|
60 | var validator = new Validator(null, { name: 'required' });
|
61 | validator.fails();
|
62 | });
|
63 | });
|