UNPKG

1.19 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('lang / messages', function() {
10 it('should default to english', function() {
11 expect(Validator.getDefaultLang()).to.equal('en');
12 });
13
14 it('should be able to change lang', function() {
15 var oldLang = Validator.getDefaultLang();
16 Validator.useLang('ru');
17 expect(Validator.getDefaultLang()).to.equal('ru');
18 Validator.useLang(oldLang);
19 });
20
21 it('should be able to add custom', function() {
22 var oldLang = Validator.getDefaultLang();
23 var rawMessages = {
24 required: 'Le nkundla iyadingeka',
25 attributes: {}
26 };
27 Validator.setMessages('zu', rawMessages);
28 Validator.useLang('zu');
29 var validator = new Validator({
30 zip: ''
31 }, {
32 zip: 'required'
33 });
34
35 var messages = Validator.getMessages('zu');
36 expect(messages).to.equal(rawMessages);
37 expect(validator.fails()).to.be.true;
38 expect(validator.errors.first('zip')).to.equal('Le nkundla iyadingeka');
39 Validator.useLang(oldLang);
40 });
41});