Skip to content

Commit 71cd51a

Browse files
Added two new tests where an object is used as data source
1 parent e138c72 commit 71cd51a

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

test/localize_test.coffee

+15
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,18 @@ do ($ = jQuery) ->
203203
t = localizableTagWithRel("p", "en_us_message", text: "en-US not loaded")
204204
t.localize("test", opts).localizePromise.then ->
205205
assert.equal t.text(), "en-US not loaded"
206+
207+
# Ref: https://github.com/coderifous/jquery-localize/issues/62
208+
module "Using object as data source"
209+
210+
asyncTest "basic tag text substitution using object as data source", (assert) ->
211+
obj = { "basic": "basic success" }
212+
t = localizableTagWithRel("p", "basic", text: "basic fail")
213+
t.localize(obj).localizePromise.then ->
214+
assert.equal t.text(), "basic success"
215+
216+
asyncTest "don't replace tag text if matching object property contains a function", (assert) ->
217+
obj = { "function": (->) }
218+
t = localizableTagWithRel("p", "function", text: "This text should remain unchanged")
219+
t.localize(obj).localizePromise.then ->
220+
assert.equal t.text(), "This text should remain unchanged"

test/localize_test.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@
348348
return assert.equal(t.text(), "en not loaded");
349349
});
350350
});
351-
return asyncTest("skipping region language using array match", function(assert) {
351+
asyncTest("skipping region language using array match", function(assert) {
352352
var opts, t;
353353
opts = {
354354
language: "en-US",
@@ -362,4 +362,29 @@
362362
return assert.equal(t.text(), "en-US not loaded");
363363
});
364364
});
365+
module("Using object as data source");
366+
asyncTest("basic tag text substitution using object as data source", function(assert) {
367+
var obj, t;
368+
obj = {
369+
"basic": "basic success"
370+
};
371+
t = localizableTagWithRel("p", "basic", {
372+
text: "basic fail"
373+
});
374+
return t.localize(obj).localizePromise.then(function() {
375+
return assert.equal(t.text(), "basic success");
376+
});
377+
});
378+
return asyncTest("don't replace tag text if matching object property contains a function", function(assert) {
379+
var obj, t;
380+
obj = {
381+
"function": (function() {})
382+
};
383+
t = localizableTagWithRel("p", "function", {
384+
text: "This text should remain unchanged"
385+
});
386+
return t.localize(obj).localizePromise.then(function() {
387+
return assert.equal(t.text(), "This text should remain unchanged");
388+
});
389+
});
365390
})(jQuery);

0 commit comments

Comments
 (0)