Skip to content

Instantly share code, notes, and snippets.

@drewfish
Created February 5, 2014 20:52
Show Gist options
  • Save drewfish/8832805 to your computer and use it in GitHub Desktop.
Save drewfish/8832805 to your computer and use it in GitHub Desktop.
it('for intlMessage', function () {
var tmpl = '{@intl formats=intl.formats}{@intlMessage _msg=MSG product=PRODUCT price=PRICE deadline=DEADLINE timeZone=TZ/}{/intl}',
ctx = {
MSG: '{product} cost {price, usd} (or {price, eur}) if ordered by {deadline, date, medium}',
intl: {
formats: {
eur: function(val, locale, options) {
return new intl.NumberFormat(locale, {
style: 'currency',
currency: 'EUR'
}).format(val);
},
usd: function(val, locale, options) {
return new intl.NumberFormat(locale, {
style: 'currency',
currency: 'USD'
}).format(val);
},
ymd: function(val, locale, options) {
return new intl.DateTimeFormat(locale, {
year: 'numeric',
month: 'numeric',
day: 'numeric'
}).format(val);
}
}
},
PRODUCT: 'oranges',
PRICE: 40000.004,
DEADLINE: timeStamp,
TZ: 'UTC'
},
expected = "oranges cost $40,000.00 (or €40,000.00) if ordered by Jan 23, 2014";
Dust.renderSource(tmpl, ctx, function(err, out) {
expect(out).to.equal(expected);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment