Skip to content

Localize from object #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Added two new tests where an object is used as data source
  • Loading branch information
LonelyPrincess committed Jul 9, 2017
commit 71cd51a3b4e458e351e616a0a1e9f1b8307c83f2
15 changes: 15 additions & 0 deletions test/localize_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,18 @@ do ($ = jQuery) ->
t = localizableTagWithRel("p", "en_us_message", text: "en-US not loaded")
t.localize("test", opts).localizePromise.then ->
assert.equal t.text(), "en-US not loaded"

# Ref: https://github.com/coderifous/jquery-localize/issues/62
module "Using object as data source"

asyncTest "basic tag text substitution using object as data source", (assert) ->
obj = { "basic": "basic success" }
t = localizableTagWithRel("p", "basic", text: "basic fail")
t.localize(obj).localizePromise.then ->
assert.equal t.text(), "basic success"

asyncTest "don't replace tag text if matching object property contains a function", (assert) ->
obj = { "function": (->) }
t = localizableTagWithRel("p", "function", text: "This text should remain unchanged")
t.localize(obj).localizePromise.then ->
assert.equal t.text(), "This text should remain unchanged"
27 changes: 26 additions & 1 deletion test/localize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
return assert.equal(t.text(), "en not loaded");
});
});
return asyncTest("skipping region language using array match", function(assert) {
asyncTest("skipping region language using array match", function(assert) {
var opts, t;
opts = {
language: "en-US",
Expand All @@ -362,4 +362,29 @@
return assert.equal(t.text(), "en-US not loaded");
});
});
module("Using object as data source");
asyncTest("basic tag text substitution using object as data source", function(assert) {
var obj, t;
obj = {
"basic": "basic success"
};
t = localizableTagWithRel("p", "basic", {
text: "basic fail"
});
return t.localize(obj).localizePromise.then(function() {
return assert.equal(t.text(), "basic success");
});
});
return asyncTest("don't replace tag text if matching object property contains a function", function(assert) {
var obj, t;
obj = {
"function": (function() {})
};
t = localizableTagWithRel("p", "function", {
text: "This text should remain unchanged"
});
return t.localize(obj).localizePromise.then(function() {
return assert.equal(t.text(), "This text should remain unchanged");
});
});
})(jQuery);