aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/filters.js3
-rw-r--r--test/FiltersSpec.js23
2 files changed, 20 insertions, 6 deletions
diff --git a/src/filters.js b/src/filters.js
index 5bb987d4..0437f0e0 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -118,13 +118,14 @@ angularFilter.currency = function(amount, currencySymbol){
var DECIMAL_SEP = '.';
angularFilter.number = function(number, fractionSize) {
- if (isNaN(number) || !isFinite(number)) return '';
var formats = this.$service('$locale').NUMBER_FORMATS;
return formatNumber(number, formats.PATTERNS[0], formats.GROUP_SEP,
formats.DECIMAL_SEP, fractionSize);
}
function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) {
+ if (isNaN(number) || !isFinite(number)) return '';
+
var isNegative = number < 0;
number = Math.abs(number);
var numStr = number + '',
diff --git a/test/FiltersSpec.js b/test/FiltersSpec.js
index 2673b36e..83d8aac0 100644
--- a/test/FiltersSpec.js
+++ b/test/FiltersSpec.js
@@ -83,20 +83,33 @@ describe('filter', function() {
});
describe('currency', function() {
- it('should do basic currency filtering', function() {
- var html = jqLite('<span/>');
- var context = createScope();
+ var currency, html, context;
+
+ beforeEach(function() {
+ html = jqLite('<span></span>');
+ context = createScope();
context.$element = html;
- var currency = bind(context, filter.currency);
+ currency = bind(context, filter.currency);
+ });
+ afterEach(function() {
+ dealoc(context);
+ });
+
+ it('should do basic currency filtering', function() {
expect(currency(0)).toEqual('$0.00');
expect(html.hasClass('ng-format-negative')).toBeFalsy();
expect(currency(-999)).toEqual('($999.00)');
expect(html.hasClass('ng-format-negative')).toBeTruthy();
expect(currency(1234.5678, "USD$")).toEqual('USD$1,234.57');
expect(html.hasClass('ng-format-negative')).toBeFalsy();
+ });
- dealoc(context);
+ it('should return empty string for non-numbers', function() {
+ expect(currency()).toBe('');
+ expect(html.hasClass('ng-format-negative')).toBeFalsy();
+ expect(currency('abc')).toBe('');
+ expect(html.hasClass('ng-format-negative')).toBeFalsy();
});
});