diff --git a/js/directives.js b/js/directives.js index 72cd843ce..48457bf2f 100644 --- a/js/directives.js +++ b/js/directives.js @@ -244,11 +244,11 @@ angular.module('copayApp.directives') match: '=' }, link: function(scope, elem, attrs, ctrl) { - scope.$watch(function() { - return (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || scope.match === ctrl.$modelValue; - }, function(currentValue) { - ctrl.$setValidity('match', currentValue); - }); + scope.$watch(function() { + return (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || scope.match === ctrl.$modelValue; + }, function(currentValue) { + ctrl.$setValidity('match', currentValue); + }); } }; }) diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index dbca2ce8e..a3fd59a24 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -202,4 +202,37 @@ describe("Unit: Testing Directives", function() { }); }); + + describe('Match Password Inputs', function() { + beforeEach(inject(function($compile, $rootScope) { + $scope = $rootScope; + $rootScope.availableBalance = 1000; + var element = angular.element( + '
' + + '' + + '' + + '
' + ); + $scope.model = { + walletPassword: null, + walletPasswordConfirm: null + }; + $compile(element)($scope); + $scope.$digest(); + form = $scope.form; + })); + it('should not validate', function() { + form.walletPassword.$setViewValue('mysecretpassword'); + form.walletPasswordConfirm.$setViewValue('mySecretPassword'); + $scope.$digest(); + expect(form.walletPasswordConfirm.$invalid).to.equal(true); + }); + it('should validate', function() { + form.walletPassword.$setViewValue('mysecretpassword123'); + form.walletPasswordConfirm.$setViewValue('mysecretpassword123'); + $scope.$digest(); + expect(form.walletPasswordConfirm.$invalid).to.equal(false); + }); + }); + });