UNPKG

966 BJavaScriptView 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('required with', function() {
10 it('should fail', function() {
11 var validator = new Validator({
12 desert: {
13 first: 'icecream'
14 },
15 flavour: ''
16 }, {
17 flavour: 'required_with:desert.first'
18 });
19 expect(validator.fails()).to.be.true;
20 expect(validator.passes()).to.be.false;
21 expect(validator.errors.first('flavour')).to.equal('The flavour field is required when desert.first is not empty.');
22 });
23
24 it('should pass', function() {
25 var validator = new Validator({
26 desert: {
27 first: 'icecream'
28 },
29 flavour: 'chocolate'
30 }, {
31 flavour: 'required_with:desert.first'
32 });
33 expect(validator.passes()).to.be.true;
34 expect(validator.fails()).to.be.false;
35 });
36});