From 77e6acb9bb7e906ba08d105ccc4fa0f0bb5b6ebf Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 25 Apr 2013 20:00:07 +0200 Subject: [PATCH] fix($dialog): fix $apply in progres on $location change --- src/dialog/dialog.js | 1 - src/dialog/test/dialog.spec.js | 31 +++++++++++++++++-------------- src/modal/test/modal.spec.js | 11 ++++++----- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/dialog/dialog.js b/src/dialog/dialog.js index 13277671cc..4a992a1a2f 100644 --- a/src/dialog/dialog.js +++ b/src/dialog/dialog.js @@ -96,7 +96,6 @@ dialogModule.provider("$dialog", function(){ this.handleLocationChange = function() { self.close(); - self.$scope.$apply(); }; } diff --git a/src/dialog/test/dialog.spec.js b/src/dialog/test/dialog.spec.js index f913451751..79e7b87685 100644 --- a/src/dialog/test/dialog.spec.js +++ b/src/dialog/test/dialog.spec.js @@ -60,10 +60,6 @@ describe('Given ui.bootstrap.dialog', function(){ provider.options({}); }; - var changeLocation = function() { - $rootScope.$broadcast('$locationChangeSuccess'); - $rootScope.$apply(); - }; var dialogShouldBeClosed = function(){ it('should not include a backdrop in the DOM', function(){ @@ -75,7 +71,7 @@ describe('Given ui.bootstrap.dialog', function(){ }); it('should return false for isOpen()', function(){ - expect(dialog.isOpen()).toBe(false); + expect(dialog.isOpen()).toBeFalsy(); }); }; @@ -292,16 +288,23 @@ describe('Given ui.bootstrap.dialog', function(){ expect($document.find('body > div.modal > div.modal-header').length).toBe(1); }); }); - - describe('When dialog is open and location changes', function(){ - beforeEach(function(){ - createDialog({template:template}); - openDialog(); - changeLocation(); - }); - dialogShouldBeClosed(); - }); + describe('When dialog is open and location changes', function () { + + var changeLocation = function () { + $rootScope.$apply(function(){ + $rootScope.$broadcast('$locationChangeSuccess'); + }); + }; + + beforeEach(function () { + createDialog({template: template}); + openDialog(); + changeLocation(); + }); + + dialogShouldBeClosed(); + }); describe('when opening it with a template containing white-space', function(){ diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index b69f3e8e6a..35cee5b9da 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -170,10 +170,11 @@ describe('Give ui.boostrap.modal', function() { expect($scope.modalShown).not.toBeTruthy(); }); - it('should update the model if the location change is successful', function() { - $rootScope.$broadcast('$locationChangeSuccess'); - $scope.$digest(); - expect($scope.modalShown).not.toBeTruthy(); - }); + it('should update the model if the location change is successful', function () { + $rootScope.$apply(function(){ + $rootScope.$broadcast('$locationChangeSuccess'); + }); + expect($scope.modalShown).toBeFalsy(); + }); }); }); \ No newline at end of file