Permalink
Browse files

Unit: Use formatted value for compound units

Fixes #838
  • Loading branch information...
EdwardSalter authored and rxaviers committed Aug 21, 2018
1 parent 5b0ebd1 commit 5e314dad376472f0e90d67fd7ad2fe4594586caf
Showing with 7 additions and 3 deletions.
  1. +1 −1 src/unit/format.js
  2. +6 −2 test/unit/unit/format.js
View
@@ -36,7 +36,7 @@ return function( value, numberFormatter, pluralGenerator, unitProperties ) {
dividendProperties = unitProperties[ 0 ];
divisorProperties = unitProperties[ 1 ];
dividend = formatMessage( dividendProperties[ pluralValue ], [ value ] );
dividend = formatMessage( dividendProperties[ pluralValue ], [ formattedValue ] );
divisor = formatMessage( divisorProperties.one, [ "" ] ).trim();
return formatMessage( compoundUnitPattern, [ dividend, divisor ] );
View
@@ -33,7 +33,7 @@ QUnit.assert.unitFormat = function ( value, unit, options, expected ) {
var unitProps = unitProperties( unit, options.form, cldr );
this.equal(
formatUnit( value, stubNumberFormatter, oneOrOtherPluralGenerator, unitProps ),
formatUnit( value, options.numberFormatter || stubNumberFormatter, oneOrOtherPluralGenerator, unitProps ),
expected
);
};
@@ -107,11 +107,15 @@ QUnit.test( "Compound form (without category)", function ( assert ) {
assert.unitFormat( 100, "mile-per-hour", { form: "long" }, "100 miles per hour" );
});
QUnit.test( "Compund form (wihout precomputed)", function ( assert ) {
QUnit.test( "Compound form (without precomputed)", function ( assert ) {
assert.unitFormat( 1, "length-foot-per-second", { form: "long" }, "1 foot per second" );
assert.unitFormat( 100, "length-foot-per-second", { form: "long" }, "100 feet per second" );
assert.unitFormat( 1, "megabyte-per-second", { form: "narrow" }, "1MB/s" );
assert.unitFormat( 100, "megabyte-per-second", { form: "narrow" }, "100MB/s" );
assert.unitFormat( 1.2345678910, "megabyte-per-second",
{ form: "narrow", numberFormatter: function (number) { return number.toFixed(1); }},
"1.2MB/s" );
});
QUnit.test( "Compound form (short)", function ( assert ) {

0 comments on commit 5e314da

Please sign in to comment.