diff --git a/src/dropdown/dropdown.js b/src/dropdown/dropdown.js index 8f03186160..5363eb1665 100644 --- a/src/dropdown/dropdown.js +++ b/src/dropdown/dropdown.js @@ -128,8 +128,11 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position']) }); } - $animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass); - + $animate[isOpen ? 'addClass' : 'removeClass'](self.$element, openClass).then(function() { + if (angular.isDefined(isOpen) && isOpen !== wasOpen) { + toggleInvoker($scope, { open: !!isOpen }); + } + }); if ( isOpen ) { scope.focusToggleElement(); dropdownService.open( scope ); @@ -138,9 +141,6 @@ angular.module('ui.bootstrap.dropdown', ['ui.bootstrap.position']) } setIsOpen($scope, isOpen); - if (angular.isDefined(isOpen) && isOpen !== wasOpen) { - toggleInvoker($scope, { open: !!isOpen }); - } }); $scope.$on('$locationChangeSuccess', function() { diff --git a/src/dropdown/test/dropdown.spec.js b/src/dropdown/test/dropdown.spec.js index 8438aca550..20ea4d875c 100644 --- a/src/dropdown/test/dropdown.spec.js +++ b/src/dropdown/test/dropdown.spec.js @@ -1,12 +1,13 @@ describe('dropdownToggle', function() { - var $compile, $rootScope, $document, element; + var $compile, $rootScope, $document, element, $browser; beforeEach(module('ui.bootstrap.dropdown')); - beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) { + beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$browser_) { $compile = _$compile_; $rootScope = _$rootScope_; $document = _$document_; + $browser = _$browser_; })); afterEach(function() { @@ -296,9 +297,11 @@ describe('dropdownToggle', function() { it('should call it correctly when toggles', function() { $rootScope.isopen = true; $rootScope.$digest(); + $browser.defer.flush(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(true); clickDropdownToggle(); + $browser.defer.flush(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(false); }); }); @@ -312,16 +315,19 @@ describe('dropdownToggle', function() { }); it('should not have been called initially', function() { + $browser.defer.flush(); expect($rootScope.toggleHandler).not.toHaveBeenCalled(); }); it('should call it correctly when toggles', function() { $rootScope.isopen = false; $rootScope.$digest(); + $browser.defer.flush(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(false); $rootScope.isopen = true; $rootScope.$digest(); + $browser.defer.flush(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(true); }); }); @@ -334,14 +340,17 @@ describe('dropdownToggle', function() { }); it('should not have been called initially', function() { + $browser.defer.flush(); expect($rootScope.toggleHandler).not.toHaveBeenCalled(); }); it('should call it when clicked', function() { clickDropdownToggle(); + $browser.defer.flush(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(true); clickDropdownToggle(); + $browser.defer.flush(); expect($rootScope.toggleHandler).toHaveBeenCalledWith(false); }); });