From 6cfc724ec26c2a1c6091b3a18fcc8439dd4a6a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ney=20Sim=C3=B5es?= Date: Sat, 23 Sep 2017 11:18:52 -0300 Subject: [PATCH] fix(uiMoneyMask): return null should handle corner cases (#293) BREAKING CHANGE uiMoneyMask used to return the input value when empty now it will return null --- src/global/money/money.js | 2 +- src/global/money/money.test.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/global/money/money.js b/src/global/money/money.js index 8979346e..2b1f51f8 100644 --- a/src/global/money/money.js +++ b/src/global/money/money.js @@ -73,7 +73,7 @@ function MoneyMaskDirective($locale, $parse, PreFormatters) { function parser(value) { if (ctrl.$isEmpty(value)) { - return value; + return null; } var actualNumber = value.replace(/[^\d]+/g,''), formatedValue; diff --git a/src/global/money/money.test.js b/src/global/money/money.test.js index 7ad38095..eadc5cf1 100644 --- a/src/global/money/money.test.js +++ b/src/global/money/money.test.js @@ -159,7 +159,6 @@ describe('ui-money-mask', function() { var model = input.controller('ngModel'); var tests = [ - {modelValue: '', viewValue: ''}, {modelValue: '0', viewValue: '$ 0.00'}, {modelValue: '0.0', viewValue: '$ 0.00'}, {modelValue: 0, viewValue: '$ 0.00'}, @@ -173,6 +172,22 @@ describe('ui-money-mask', function() { expect(model.$viewValue).toBe(test.viewValue); }); + it('should return null if $isEmpty value', function() { + var input = TestUtil.compile('', {}); + var model = input.controller('ngModel'); + var tests = [ + {modelValue: '', viewValue: ''}, + {modelValue: null, viewValue: null}, + {modelValue: NaN, viewValue: NaN} + ]; + + tests.forEach(function(test) { + $rootScope.model = test.modelValue; + $rootScope.$digest(); + expect(model.$viewValue).toBe(null); + }); + }); + it('should ignore non digits', function() { var input = TestUtil.compile('', {}); var model = input.controller('ngModel');