UNPKG

1.89 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('email validation rule', function() {
10 it('should pass with the email address: johndoe@gmail.com', function() {
11 var validator = new Validator({
12 email: 'johndoe@gmail.com'
13 }, {
14 email: 'email'
15 });
16 expect(validator.passes()).to.be.true;
17 });
18
19 it('should fail with the email address: johndoe.gmail.com', function() {
20 var validator = new Validator({
21 email: 'johndoe.gmail.com'
22 }, {
23 email: 'email'
24 });
25 expect(validator.fails()).to.be.true;
26 });
27
28 it('should fail with the email address: johndoe@gmail', function() {
29 var validator = new Validator({
30 email: 'johndoe@gmail'
31 }, {
32 email: 'email'
33 });
34 expect(validator.fails()).to.be.true;
35 });
36
37 it('should fail when the email address contains whitespace only and is required', function() {
38 var validator = new Validator({
39 email: ' '
40 }, {
41 email: 'required|email'
42 });
43 expect(validator.fails()).to.be.true;
44 });
45
46 it('should pass when the field is an empty string', function() {
47 var validator = new Validator({
48 email: ''
49 }, {
50 email: 'email'
51 });
52 expect(validator.passes()).to.be.true;
53 });
54
55 it('should pass when the field does not exist', function() {
56 var validator = new Validator({}, {
57 email: 'email'
58 });
59 expect(validator.passes()).to.be.true;
60 expect(validator.fails()).to.be.false;
61 });
62
63 it('should pass with first.last@example.com', function() {
64 var validator = new Validator({
65 email: 'first.last@example.com'
66 }, {
67 email: 'email'
68 });
69
70 expect(validator.passes()).to.be.true;
71 expect(validator.fails()).to.be.false;
72 });
73});