Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($locale): Allow currency filter to fall back to maxFrac from locale #10179

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @param {number} amount Input to filter.
* @param {string=} symbol Currency symbol or identifier to be displayed.
* @param {number=} fractionSize Number of decimal places to round the amount to.
* @param {number=} fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale
* @returns {string} Formatted number.
*
*
Expand Down Expand Up @@ -61,8 +61,7 @@ function currencyFilter($locale) {
}

if (isUndefined(fractionSize)) {
// TODO: read the default value from the locale file
fractionSize = 2;
fractionSize = formats.PATTERNS[1].maxFrac;
}

// if null or undefined pass it through
Expand Down
6 changes: 6 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ describe('filters', function() {
expect(currency(0.008)).toBe('$0.01');
expect(currency(0.003)).toBe('$0.00');
});

it('should set the default fraction size to the max fraction size of the locale value', inject(function($locale) {
$locale.NUMBER_FORMATS.PATTERNS[1].maxFrac = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you either use jasmine's mocking library or create a $locale mock for this test instead of trying to reset the value at the end of the test?

reason: if the expectations fail the state won't be restored and that will make all the subsequent tests fail and it will be hard to find the cause.


expect(currency(1.07)).toBe('$1.1');
}));
});


Expand Down