File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -203,3 +203,18 @@ do ($ = jQuery) ->
203
203
t = localizableTagWithRel (" p" , " en_us_message" , text : " en-US not loaded" )
204
204
t .localize (" test" , opts).localizePromise .then ->
205
205
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"
Original file line number Diff line number Diff line change 348
348
return assert . equal ( t . text ( ) , "en not loaded" ) ;
349
349
} ) ;
350
350
} ) ;
351
- return asyncTest ( "skipping region language using array match" , function ( assert ) {
351
+ asyncTest ( "skipping region language using array match" , function ( assert ) {
352
352
var opts , t ;
353
353
opts = {
354
354
language : "en-US" ,
362
362
return assert . equal ( t . text ( ) , "en-US not loaded" ) ;
363
363
} ) ;
364
364
} ) ;
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
+ } ) ;
365
390
} ) ( jQuery ) ;
You can’t perform that action at this time.
0 commit comments