Skip to content

Commit

Permalink
fix(uiMoneyMask): return null should handle corner cases (#293)
Browse files Browse the repository at this point in the history
BREAKING CHANGE uiMoneyMask used to return the input value when empty now it will return null
  • Loading branch information
neysimoes authored and assisrafael committed Sep 23, 2017
1 parent b251a61 commit 6cfc724
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/global/money/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion src/global/money/money.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand All @@ -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('<input ng-model="model" ui-money-mask>', {});
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('<input ng-model="model" ui-money-mask>', {});
var model = input.controller('ngModel');
Expand Down

0 comments on commit 6cfc724

Please sign in to comment.