handlebars-i18n 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,569 @@
1
+ /**
2
+ * Tests for handlebars-i18n.js
3
+ *
4
+ * usage:
5
+ * $ cd test
6
+ * $ npm run test
7
+ */
8
+
9
+ const assert = require('chai').assert;
10
+ const expect = require('chai').expect;
11
+
12
+ const Handlebars = require('handlebars');
13
+ const i18next = require('i18next');
14
+ const HandlebarsI18n = require('../dist/handlebars-i18n');
15
+
16
+
17
+ describe('handlebars-i18n Test', function() {
18
+
19
+ const i18nInitObj = {
20
+ resources : {
21
+ 'en' : {
22
+ translation : {
23
+ 'key1': 'What is good?',
24
+ 'key2': '{{what}} is {{adverb}}.'
25
+ }
26
+ },
27
+ 'de' : {
28
+ translation: {
29
+ 'key1': 'Was ist gut?',
30
+ 'key2': '{{what}} ist {{adverb}}.'
31
+ }
32
+ }
33
+ },
34
+ lng : 'en'
35
+ };
36
+
37
+ const hI18n = HandlebarsI18n.init();
38
+
39
+
40
+ // -- Tests for method init() -- //
41
+
42
+ it('after method call init() should return an object (HandlebarsEnvironment)', function() {
43
+ assert.isObject(hI18n);
44
+ });
45
+
46
+ it('after method call init() HandlebarsEnvironment object should have a function __', function() {
47
+ assert.isFunction(hI18n.helpers.__);
48
+ });
49
+
50
+ it('after method call init() HandlebarsEnvironment object should have a function _locale', function() {
51
+ assert.isFunction(hI18n.helpers._locale);
52
+ });
53
+
54
+ it('after method call init() HandlebarsEnvironment object should have a function localeIs', function() {
55
+ assert.isFunction(hI18n.helpers.localeIs);
56
+ });
57
+
58
+ it('after method call init() HandlebarsEnvironment object should have a function _date', function() {
59
+ assert.isFunction(hI18n.helpers._date);
60
+ });
61
+
62
+ it('after method call init() HandlebarsEnvironment object should have a function _num', function() {
63
+ assert.isFunction(hI18n.helpers._num);
64
+ });
65
+
66
+ it('after method call init() HandlebarsEnvironment object should have a function _price', function() {
67
+ assert.isFunction(hI18n.helpers._price);
68
+ });
69
+
70
+ // -- Tests for method init() with override Argument -- //
71
+
72
+ it('after method call init(overrideHndlbrs) with custom handlebars Object, HandlebarsEnvironment object should have custom function foo', function() {
73
+ const HandlebarsModified = require('handlebars');
74
+ HandlebarsModified.registerHelper('foo', function() { return true });
75
+ const hI18nMod = HandlebarsI18n.init(HandlebarsModified);
76
+ assert.isFunction(hI18nMod.helpers.foo);
77
+ });
78
+
79
+
80
+ // -- Tests for function _locale -- //
81
+
82
+ it('expecting function _locale to be [undefined] as long as no language was set with i18next.init', function() {
83
+ i18next.init(); // empty init
84
+ const res = hI18n.helpers._locale();
85
+ expect(res).to.be.undefined;
86
+ });
87
+
88
+ it('function _locale should return "en" if language is specified as "en" by init Object', function() {
89
+ i18next.init(i18nInitObj); // initialize with data
90
+ const res = hI18n.helpers._locale();
91
+ assert.equal('en', res);
92
+ });
93
+
94
+ it('function _locale should return "de" after language change to "de"', function() {
95
+ i18next.changeLanguage('de');
96
+ const res = hI18n.helpers._locale();
97
+ assert.equal('de', res);
98
+ });
99
+
100
+
101
+ // -- Tests for function isLocale -- //
102
+
103
+ it('function isLocale should return TRUE when current language is set to "en" and given "en" as parameter', function() {
104
+ i18next.changeLanguage('en');
105
+ const res = hI18n.helpers.localeIs('en');
106
+ assert.equal(true, res);
107
+ });
108
+
109
+ it('function isLocale should return FALSE when current language is set to "en" and given "someOther" as parameter', function() {
110
+ i18next.changeLanguage('en');
111
+ const res = hI18n.helpers.localeIs('someOther');
112
+ assert.equal(false, res);
113
+ });
114
+
115
+
116
+ // -- Tests for function __ -- //
117
+
118
+ it('expecting __ to throw error when called with no parameter', function() {
119
+ expect(function() { hI18n.helpers.__() }).to.throw("Cannot read property 'hash' of undefined");
120
+ });
121
+
122
+ it('function __ should return a SafeString object with property "string" where "string" returns the first argument given to __', function() {
123
+ const res = hI18n.helpers.__("someNoneExitingKey", { hash: {} });
124
+ assert.equal("someNoneExitingKey", res.string);
125
+ });
126
+
127
+ it('function __ should return a SafeString object with property "string" where "string" contains "What is good?!', function() {
128
+ const res = hI18n.helpers.__("key1", { hash: {} });
129
+ assert.equal("What is good?", res.string);
130
+ });
131
+
132
+ it('function __ should return a SafeString object with property "string" where "string" contains "Was ist gut?"', function() {
133
+ i18next.changeLanguage('de');
134
+ const res = hI18n.helpers.__("key1", { hash: {} });
135
+ assert.equal("Was ist gut?", res.string);
136
+ });
137
+
138
+ it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next is good."', function() {
139
+ i18next.changeLanguage('en');
140
+ const res = hI18n.helpers.__("key2", { hash: { what : "handlebarsI18next", adverb : "good" } });
141
+ assert.equal("handlebarsI18next is good.", res.string);
142
+ });
143
+
144
+ it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next ist gut."', function() {
145
+ i18next.changeLanguage('de');
146
+ const res = hI18n.helpers.__("key2", { hash: { what: "handlebarsI18next", adverb: "gut" } });
147
+ assert.equal("handlebarsI18next ist gut.", res.string);
148
+ });
149
+
150
+
151
+ // -- Tests for function _date -- //
152
+
153
+ it('expect function _date to throw error when called with invalid date parameter', function() {
154
+ expect(function() { hI18n.helpers._date('someStrangeString') }).to.throw("Invalid valid date passed to format");
155
+ });
156
+
157
+ it('function _date should return today\'s date in Intl default format when called without parameter', function() {
158
+ i18next.changeLanguage('en');
159
+ const today = new Date();
160
+ const todayFormated = new Intl.DateTimeFormat().format(today);
161
+
162
+ const res = hI18n.helpers._date();
163
+ assert.equal(todayFormated, res);
164
+ });
165
+
166
+ it('function _date should return today\'s date in Intl default format when called with parameter, "Today" or "Now" no matter of upper or lower case writing', function() {
167
+ i18next.changeLanguage('en');
168
+ const today = new Date();
169
+ const todayFormated = new Intl.DateTimeFormat().format(today);
170
+
171
+ assert.equal(todayFormated, hI18n.helpers._date("today"));
172
+ assert.equal(todayFormated, hI18n.helpers._date("Today"));
173
+ assert.equal(todayFormated, hI18n.helpers._date("TODAY"));
174
+ assert.equal(todayFormated, hI18n.helpers._date("now"));
175
+ assert.equal(todayFormated, hI18n.helpers._date("Now"));
176
+ assert.equal(todayFormated, hI18n.helpers._date("NOW"));
177
+ });
178
+
179
+ it('function _date should return "1/1/1970" (Intl default format) when called with parameter 1 as number ', function() {
180
+ i18next.changeLanguage('en');
181
+ const res = hI18n.helpers._date(1);
182
+ assert.equal('1/1/1970', res);
183
+ });
184
+
185
+ it('function _date should return "12/17/1995" (Intl default format) when called with parameter "1995-12-17T03:24:00"', function() {
186
+ i18next.changeLanguage('en');
187
+ const res = hI18n.helpers._date('1995-12-17T03:24:00');
188
+ assert.equal('12/17/1995', res);
189
+ });
190
+
191
+ it('function _date should return "12/17/1995" (Intl default format) when called with parameter "December 17, 1995 03:24:00"', function() {
192
+ i18next.changeLanguage('en');
193
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00');
194
+ assert.equal('12/17/1995', res);
195
+ });
196
+
197
+ it('function _date should return "1/1/2020" (Intl default format) when called with parameter "[2020]"', function() {
198
+ i18next.changeLanguage('en');
199
+ const res = hI18n.helpers._date('[1995]');
200
+ assert.equal('1/1/1995', res);
201
+ });
202
+
203
+ it('function _date should return "12/1/1995" (Intl default format) when called with parameter "[2020,11]"', function() {
204
+ i18next.changeLanguage('en');
205
+ const res = hI18n.helpers._date('[1995,11]');
206
+ assert.equal('12/1/1995', res);
207
+ });
208
+
209
+ it('function _date should return "12/17/1995" (Intl default format) when called with parameter "[2020,11,17]"', function() {
210
+ i18next.changeLanguage('en');
211
+ const res = hI18n.helpers._date('[1995,11,17]');
212
+ assert.equal('12/17/1995', res);
213
+ });
214
+
215
+ it('function _date should return "12/1/95" when called with parameter "[2020,11,01] and specifying options"', function() {
216
+ i18next.changeLanguage('en');
217
+ const res = hI18n.helpers._date('[1995,11,1]', { hash: { year:"2-digit", month:"2-digit", day:"2-digit" } });
218
+ assert.equal('12/1/95', res);
219
+ });
220
+
221
+ it('function _date should return "01.12.95" when called with parameter "[2020,11,01] and specifying options an language set to "de"', function() {
222
+ i18next.changeLanguage('de');
223
+ const res = hI18n.helpers._date('[1995,11,1]', { hash: { year:"2-digit", month:"2-digit", day:"2-digit" } });
224
+ assert.equal('01.12.95', res);
225
+ });
226
+
227
+
228
+ // -- Tests for function _num -- //
229
+
230
+ it('function _num should return comma separated triples of decimals when language is "en"', function() {
231
+ i18next.changeLanguage('en');
232
+ const res = hI18n.helpers._num(4000000, { hash: {} });
233
+ assert.equal('4,000,000', res);
234
+ });
235
+
236
+ it('function _num should return dot separated triples of decimals when language is "de"', function() {
237
+ i18next.changeLanguage('de');
238
+ const res = hI18n.helpers._num(4000000, { hash: {} });
239
+ assert.equal('4.000.000', res);
240
+ });
241
+
242
+ it('function _num should return comma separated triples of decimals and 2 fraction digits"', function() {
243
+ i18next.changeLanguage('en');
244
+ const res = hI18n.helpers._num(4000000, { hash: { minimumFractionDigits : 2 } });
245
+ assert.equal('4,000,000.00', res);
246
+ });
247
+
248
+ it('function _num should return dot separated triples of decimals and 2 fraction digits when language is "de"', function() {
249
+ i18next.changeLanguage('de');
250
+ const res = hI18n.helpers._num(4000000, { hash: { minimumFractionDigits : 2 } });
251
+ assert.equal('4.000.000,00', res);
252
+ });
253
+
254
+
255
+ // -- Tests for function _price -- //
256
+
257
+ it('function _currency should return price in € written in comma separated triples of decimals and 2 fraction digits with leading currency symbol', function() {
258
+ i18next.changeLanguage('en');
259
+ const res = hI18n.helpers._price(4000000, { hash: {} });
260
+ assert.equal('€4,000,000.00', res);
261
+ });
262
+
263
+ it('function _currency should return price in € written in dot separated triples of decimals and 2 fraction digits with trailing currency symbol', function() {
264
+ i18next.changeLanguage('de');
265
+ const res = hI18n.helpers._price(4000000, { hash: {} });
266
+ assert.isString(res);
267
+ assert.equal('4.000.000,00 €', res);
268
+ });
269
+
270
+ it('function _currency should return price in ¥ written in comma separated triples of decimals with leading currency symbol', function() {
271
+ i18next.changeLanguage('en');
272
+ const res = hI18n.helpers._price(4000000, { hash: { currency: 'JPY', maximumFractionDigits: 0 } });
273
+ assert.equal('¥4,000,000', res);
274
+ });
275
+
276
+ it('function _currency should return price in ¥ written in comma separated triples of decimals with trailing currency symbol', function() {
277
+ i18next.changeLanguage('de');
278
+ const res = hI18n.helpers._price(4000000, { hash: { currency: 'JPY', maximumFractionDigits: 0 } });
279
+ assert.equal('4.000.000 ¥', res);
280
+ });
281
+
282
+
283
+ // -- Tests for method configure() -- //
284
+
285
+ it('method configure() should return false if called without argument', function() {
286
+ const configure = HandlebarsI18n.configure();
287
+ assert.isNotOk(configure);
288
+ });
289
+
290
+ it('method configure() should return false if called with empty array []', function() {
291
+ const configure = HandlebarsI18n.configure([]);
292
+ assert.isNotOk(configure);
293
+ });
294
+
295
+ it('method configure() should return false if called with only one argument', function() {
296
+ const configure = HandlebarsI18n.configure('en');
297
+ assert.isNotOk(configure);
298
+ });
299
+
300
+ it('method configure() should return false if called with language argument and invalid second argument', function() {
301
+ const configure = HandlebarsI18n.configure('en', 'somestrangeinput');
302
+ assert.isNotOk(configure);
303
+ });
304
+
305
+ it('method configure() should return false if called with language argument "en" and second argument "DateTimeFormat" and Number (invalid argument) as third', function() {
306
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', 12);
307
+ assert.isNotOk(configure);
308
+ });
309
+
310
+ it('method configure() should return true if called with language argument "en" and second argument "DateTimeFormat" and options object as third argument', function() {
311
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' } );
312
+ assert.isOk(configure);
313
+ });
314
+
315
+ it('method configure() should return true if called with arguments "en", "DateTimeFormat", { year:"numeric" } and a string as custom configuration name', function() {
316
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' }, "my-custom-conf" );
317
+ assert.isOk(configure);
318
+ });
319
+
320
+ it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional object (invalid argument)', function() {
321
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' }, {} );
322
+ assert.isNotOk(configure);
323
+ });
324
+
325
+ it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional empty string (invalid argument)', function() {
326
+ const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', { year:'numeric' }, "" );
327
+ assert.isNotOk(configure);
328
+ });
329
+
330
+
331
+ // -- Tests for method reset() -- //
332
+
333
+ it('method reset() should return TRUE if called', function() {
334
+ const res = HandlebarsI18n.reset();
335
+ assert.isOk(res);
336
+ });
337
+
338
+ it('function _num should return Intl standard format (no fraction digits) after reset() beeing called', function() {
339
+ HandlebarsI18n.configure('en', 'NumberFormat', { minimumFractionDigits:4 } );
340
+ i18next.changeLanguage('en');
341
+ HandlebarsI18n.reset();
342
+ const res = hI18n.helpers._num(4000000);
343
+ assert.equal('4,000,000', res);
344
+ });
345
+
346
+
347
+ // -- Tests for custom format configurations for function _date -- //
348
+
349
+ it('function _date when called after configure() with defined custom format (year:2-digit) should return ' +
350
+ 'date "95" when language is "en"', function() {
351
+ HandlebarsI18n.configure('en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format');
352
+ i18next.changeLanguage('en');
353
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
354
+ assert.equal('95', res);
355
+ });
356
+
357
+ it('function _date when called after configure() with defined custom format (year:2-digit) given as ARRAY should return ' +
358
+ 'date "12/17/95" when language is "en"', function() {
359
+ HandlebarsI18n.configure(['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format']);
360
+ i18next.changeLanguage('en');
361
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
362
+ assert.equal('95', res);
363
+ });
364
+
365
+ it('function _date when called after configure() with defined custom format (year:2-digit) should override ' +
366
+ 'standard configuration when language is "en"', function() {
367
+ HandlebarsI18n.configure([
368
+ ['en', 'DateTimeFormat', { year:"numeric" }],
369
+ ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format']
370
+ ]);
371
+ i18next.changeLanguage('en');
372
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
373
+ assert.equal('95', res);
374
+ });
375
+
376
+ it('function _date when called after configure() with defined custom format (year:2-digit) should override ' +
377
+ 'standard configuration also when beeing defined first', function() {
378
+ HandlebarsI18n.configure([
379
+ ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format'],
380
+ ['en', 'DateTimeFormat', { year:"numeric" }]
381
+ ]);
382
+ i18next.changeLanguage('en');
383
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-custom-format'} });
384
+ assert.equal('95', res);
385
+ });
386
+
387
+ it('function _date when called after configure() should fall back to generic language format "en" when custom format is unknown' +
388
+ 'standard configuration also when beeing defined first', function() {
389
+ HandlebarsI18n.configure([
390
+ ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format'],
391
+ ['en', 'DateTimeFormat', { year:"numeric" }]
392
+ ]);
393
+ i18next.changeLanguage('en');
394
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-unknown-format'} });
395
+ assert.equal('1995', res);
396
+ });
397
+
398
+ it('function _date when called after configure() should fall back to generic language format "all" when custom format is unknown' +
399
+ 'standard configuration also when beeing defined first', function() {
400
+ HandlebarsI18n.configure([
401
+ ['all', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format'],
402
+ ['en', 'DateTimeFormat', { year:"numeric" }]
403
+ ]);
404
+ i18next.changeLanguage('en');
405
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-unknown-format'} });
406
+ assert.equal('1995', res);
407
+ });
408
+
409
+ it('function _date when called after configure() should fall back to Intl default format when custom format is unknown' +
410
+ 'standard configuration also when beeing defined first', function() {
411
+ HandlebarsI18n.reset();
412
+ HandlebarsI18n.configure([
413
+ ['en', 'DateTimeFormat', { year:"2-digit" }, 'my-custom-format']
414
+ ]);
415
+ i18next.changeLanguage('en');
416
+ const res = hI18n.helpers._date('December 17, 1995 03:24:00', { hash: { format: 'my-unknown-format'} });
417
+ assert.equal('12/17/1995', res);
418
+ });
419
+
420
+
421
+ // -- Tests for custom format configurations for function _num -- //
422
+
423
+ it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
424
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
425
+ HandlebarsI18n.configure('en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format');
426
+ i18next.changeLanguage('en');
427
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
428
+ assert.equal('4,000,000.0000', res);
429
+ });
430
+
431
+ it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) given as ARRAY should return ' +
432
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
433
+ HandlebarsI18n.configure(['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format']);
434
+ i18next.changeLanguage('en');
435
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
436
+ assert.equal('4,000,000.0000', res);
437
+ });
438
+
439
+ it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should override' +
440
+ 'standard configuration when language is "en"', function() {
441
+ HandlebarsI18n.configure([
442
+ ['en', 'NumberFormat', { maximumFractionDigits:1 }],
443
+ ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format']
444
+ ]);
445
+ i18next.changeLanguage('en');
446
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
447
+ assert.equal('4,000,000.0000', res);
448
+ });
449
+
450
+ it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should override' +
451
+ 'standard configuration also when being defined first', function() {
452
+ HandlebarsI18n.configure([
453
+ ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format'],
454
+ ['en', 'NumberFormat', { maximumFractionDigits:1 }]
455
+ ]);
456
+ i18next.changeLanguage('en');
457
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-custom-format'} });
458
+ assert.equal('4,000,000.0000', res);
459
+ });
460
+
461
+ it('function _num when called after configure() should fall back to standard language format "en" when custom format is unknown', function() {
462
+ HandlebarsI18n.configure([
463
+ ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format'],
464
+ ['en', 'NumberFormat', { minimumFractionDigits:1 }]
465
+ ]);
466
+ i18next.changeLanguage('en');
467
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-unknown-format'} });
468
+ assert.equal('4,000,000.0', res);
469
+ });
470
+
471
+ it('function _num when called after configure() should fall back to standard language format "all" when custom format is unknown', function() {
472
+ HandlebarsI18n.configure([
473
+ ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format'],
474
+ ['all', 'NumberFormat', { minimumFractionDigits:1 }]
475
+ ]);
476
+ i18next.changeLanguage('en');
477
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-unknown-format'} });
478
+ assert.equal('4,000,000.0', res);
479
+ });
480
+
481
+ it('function _num when called after configure() should fall back to Intl default when custom format is unknown', function() {
482
+ HandlebarsI18n.reset();
483
+ HandlebarsI18n.configure([
484
+ ['en', 'NumberFormat', { minimumFractionDigits:4 }, 'my-custom-format']
485
+ ]);
486
+ i18next.changeLanguage('en');
487
+ const res = hI18n.helpers._num(4000000, { hash: { format: 'my-unknown-format'} });
488
+ assert.equal('4,000,000', res);
489
+ });
490
+
491
+
492
+ // -- Tests for custom format configurations for function _price -- //
493
+
494
+ it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
495
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
496
+ HandlebarsI18n.configure('en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format');
497
+ i18next.changeLanguage('en');
498
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
499
+ assert.equal('€2.000', res);
500
+ });
501
+
502
+ it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
503
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
504
+ HandlebarsI18n.configure('en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format');
505
+ i18next.changeLanguage('en');
506
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
507
+ assert.equal('€2.000', res);
508
+ });
509
+
510
+ it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) given as ARRAY should return ' +
511
+ 'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
512
+ HandlebarsI18n.configure(['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format']);
513
+ i18next.changeLanguage('en');
514
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
515
+ assert.equal('€2.000', res);
516
+ });
517
+
518
+ it('function _price when called after configure() with defined custom format (minimumFractionDigits:3) should override' +
519
+ 'standard configuration when language is "en"', function() {
520
+ HandlebarsI18n.configure([
521
+ ['en', 'PriceFormat', { currency:'USD'}],
522
+ ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format']
523
+ ]);
524
+ i18next.changeLanguage('en');
525
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
526
+ assert.equal('€2.000', res);
527
+ });
528
+
529
+ it('function _price when called after configure() with defined custom format (minimumFractionDigits:3) should override' +
530
+ 'standard configuration also when being defined first', function() {
531
+ HandlebarsI18n.configure([
532
+ ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format'],
533
+ ['en', 'PriceFormat', { currency:'USD'}]
534
+ ]);
535
+ i18next.changeLanguage('en');
536
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-custom-format'} });
537
+ assert.equal('€2.000', res);
538
+ });
539
+
540
+ it('function _price when called after configure() should fall back to standard language format "en" when custom format is unknown', function() {
541
+ HandlebarsI18n.configure([
542
+ ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format'],
543
+ ['en', 'PriceFormat', { currency:'USD'}]
544
+ ]);
545
+ i18next.changeLanguage('en');
546
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-unknown-format'} });
547
+ assert.equal('$2.00', res);
548
+ });
549
+
550
+ it('function _price when called after configure() should fall back to standard language format "all" when custom format is unknown', function() {
551
+ HandlebarsI18n.configure([
552
+ ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format'],
553
+ ['all', 'PriceFormat', { currency:'USD'}]
554
+ ]);
555
+ i18next.changeLanguage('en');
556
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-unknown-format'} });
557
+ assert.equal('$2.00', res);
558
+ });
559
+
560
+ it('function _price when called after configure() should fall back to Intl default when custom format is unknown', function() {
561
+ HandlebarsI18n.configure([
562
+ ['en', 'PriceFormat', { currency:'EUR', minimumFractionDigits:3 }, 'my-custom-format']
563
+ ]);
564
+ i18next.changeLanguage('en');
565
+ const res = hI18n.helpers._price(2, { hash: { format: 'my-unknown-format'} });
566
+ assert.equal('$2.00', res);
567
+ });
568
+
569
+ });