diff --git a/test/validation-ui-tests.js b/test/validation-ui-tests.js index 8cb3e10c..fe6dd034 100644 --- a/test/validation-ui-tests.js +++ b/test/validation-ui-tests.js @@ -196,6 +196,40 @@ QUnit.test('Inserting Messages Works', function(assert) { assert.equal(msg, 'This field is required.', msg); }); +QUnit.test('Translating Messages Works', function(assert) { + addTestHtml(''); + var $testInput = $('#myTestInput'), + msg; + + var vm = { + firstName: ko.observable('').extend({ required: true }) + }; + + applyTestBindings(vm); + + var originalMessage = ko.unwrap(ko.validation.rules.required.message), + translatedMessage = 'translation test'; + ko.validation.localize({'required': translatedMessage}); + + $testInput.val('a').change().val('').change(); + msg = $testInput.siblings().first().text(); + + assert.equal(msg, translatedMessage, msg); + + translatedMessage = 'translation test 2'; + ko.validation.localize({'required': translatedMessage}); + + msg = $testInput.siblings().first().text(); + assert.equal(msg, translatedMessage, msg); + + $testInput.val('a').change().val('').change(); + msg = $testInput.siblings().first().text(); + + assert.equal(msg, translatedMessage, msg); + + ko.validation.localize({'required': originalMessage}); +}); + QUnit.test('Inserting Messages with HTML Works', function(assert) { ko.validation.init({