UNPKG

1.33 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('confirmed validation rule', function() {
10 it('should fail without a matching confirmation field for the field under validation', function() {
11 var validator = new Validator({
12 password: 'abc'
13 }, {
14 password: 'confirmed'
15 });
16 expect(validator.passes()).to.be.false;
17 expect(validator.fails()).to.be.true;
18 });
19
20 it('should fail without a matching confirmation field for the field under validation', function() {
21 var validator = new Validator({
22 password: 'abc',
23 password_confirmation: 'abcd'
24 }, {
25 password: 'confirmed'
26 });
27 expect(validator.passes()).to.be.false;
28 expect(validator.fails()).to.be.true;
29 expect(validator.errors.first('password')).to.equal('The password confirmation does not match.');
30 });
31
32 it('should pass with a matching confirmation field for the field under validation', function() {
33 var validator = new Validator({
34 password: 'abc',
35 password_confirmation: 'abc'
36 }, {
37 password: 'confirmed'
38 });
39 expect(validator.passes()).to.be.true;
40 expect(validator.fails()).to.be.false;
41 });
42});