Skip to content

Commit

Permalink
Fix globalizejs#838: formatUnit now displays the formatted number val…
Browse files Browse the repository at this point in the history
…ue when using a compound unit
  • Loading branch information
Edward Salter committed Jul 27, 2018
1 parent 5b0ebd1 commit b19dc04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/unit/format.js
Expand Up @@ -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 ] );
Expand Down
8 changes: 6 additions & 2 deletions test/unit/unit/format.js
Expand Up @@ -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
);
};
Expand Down Expand Up @@ -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 ) {
Expand Down

0 comments on commit b19dc04

Please sign in to comment.