UNPKG

2.22 kBJavaScriptView 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('accepted validation rule', function() {
10 it('should pass if the value is yes', function() {
11 var validator = new Validator({
12 terms: 'yes'
13 }, {
14 terms: 'accepted'
15 });
16 expect(validator.passes()).to.be.true;
17 expect(validator.fails()).to.be.false;
18 });
19
20 it('should pass if the value is on', function() {
21 var validator = new Validator({
22 terms: 'on'
23 }, {
24 terms: 'accepted'
25 });
26 expect(validator.passes()).to.be.true;
27 expect(validator.fails()).to.be.false
28 });
29
30 it('should pass if the value is the number 1', function() {
31 var validator = new Validator({
32 terms: 1
33 }, {
34 terms: 'accepted'
35 });
36 expect(validator.passes()).to.be.true;
37 expect(validator.fails()).to.be.false;
38 });
39
40 it('should pass if the value is the string 1', function() {
41 var validator = new Validator({
42 terms: '1'
43 }, {
44 terms: 'accepted'
45 });
46 expect(validator.passes()).to.be.true;
47 expect(validator.fails()).to.be.false;
48 });
49
50 it('should pass if the value is a boolean true', function() {
51 var validator = new Validator({
52 terms: true
53 }, {
54 terms: 'accepted'
55 });
56 expect(validator.passes()).to.be.true;
57 expect(validator.fails()).to.be.false;
58 });
59
60 it('should fail if the value is not 1, on, or yes', function() {
61 var validator = new Validator({
62 terms: '10'
63 }, {
64 terms: 'accepted'
65 });
66 expect(validator.passes()).to.be.false;
67 expect(validator.fails()).to.be.true;
68 });
69
70 it('should fail if the value is an empty string', function() {
71 var validator = new Validator({
72 terms: ''
73 }, {
74 terms: 'accepted'
75 });
76 expect(validator.passes()).to.be.false;
77 expect(validator.fails()).to.be.true;
78 });
79
80 it('should fail if the value is undefined', function() {
81 var validator = new Validator({}, {
82 terms: 'accepted'
83 });
84 expect(validator.passes()).to.be.false;
85 expect(validator.fails()).to.be.true;
86 });
87});