diff --git a/js/angular/directive/navButtons.js b/js/angular/directive/navButtons.js index 6d6dcbee6bf..7bf7881ad6d 100644 --- a/js/angular/directive/navButtons.js +++ b/js/angular/directive/navButtons.js @@ -58,7 +58,10 @@ IonicModule //Append buttons to navbar ionic.requestAnimationFrame(function() { - $animate.enter(buttons, navElement); + //If the scope is destroyed before raf runs, be sure not to enter + if (!$scope.$$destroyed) { + $animate.enter(buttons, navElement); + } }); //When our ion-nav-buttons container is destroyed, diff --git a/test/unit/angular/directive/navBackButton.unit.js b/test/unit/angular/directive/navBackButton.unit.js index 8a76dbe4fc8..33bf86ebb07 100644 --- a/test/unit/angular/directive/navBackButton.unit.js +++ b/test/unit/angular/directive/navBackButton.unit.js @@ -1,15 +1,5 @@ describe('ionNavBackButton directive', function() { - beforeEach(module('ionic', function($compileProvider) { - $compileProvider.directive('needsScroll', function() { - return { - //Test if the buttons are 'children of ionScroll' when compiled - require: '^$ionicScroll', - link: function(scope, element, attrs, ctrl) { - element.data('scrollCtrl', ctrl); - } - }; - }); - })); + beforeEach(module('ionic')); function setup(attr, content) { var el; @@ -24,27 +14,6 @@ describe('ionNavBackButton directive', function() { return el; } - it('ionNavButtons should compile buttons with same scope & access the same data on compile', inject(function($compile, $rootScope) { - var el = $compile('
' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
')($rootScope.$new()); - $rootScope.$apply(); - expect(el.find('ion-content').children().scope()) - .toBe(el.find('.left-buttons button').scope()); - - //Test if the button was compiled able to access the parents of ion-nav-buttons - var scrollCtrl = el.find('ion-content').controller('$ionicScroll'); - expect(scrollCtrl).toBeTruthy(); - expect(el.find('button[needs-scroll]').data('scrollCtrl')).toBe(scrollCtrl); - })); - it('should error without a parent ionNavBar', inject(function($compile, $rootScope) { expect(function() { $compile('')($rootScope); diff --git a/test/unit/angular/directive/navButtons.unit.js b/test/unit/angular/directive/navButtons.unit.js new file mode 100644 index 00000000000..62bb714a8a9 --- /dev/null +++ b/test/unit/angular/directive/navButtons.unit.js @@ -0,0 +1,83 @@ +ddescribe('ionNavButtons directive', function() { + + beforeEach(module('ionic', function($compileProvider) { + $compileProvider.directive('needsScroll', function() { + return { + //Test if the buttons are 'children of ionScroll' when compiled + require: '^$ionicScroll', + link: function(scope, element, attrs, ctrl) { + element.data('scrollCtrl', ctrl); + } + }; + }); + })); + beforeEach(function() { + ionic.requestAnimationFrame = function(cb) { cb(); }; + }); + + function setup(side, tpl) { + var el; + inject(function($compile, $rootScope) { + el = $compile('
' + + '' + + '' + + '' + + '' + + (tpl || '') + + '' + + '' + + '' + + '
')($rootScope.$new()); + $rootScope.$apply(); + }); + return el; + } + + it('should add buttons to left side by default', function() { + var el = setup(null, ''); + expect(jqLite(el[0].querySelector('ion-content')).children().scope().$id) + .toBe(jqLite(el[0].querySelector('.left-buttons button')).scope().$id); + + //Test if the button was compiled able to access the parents of ion-nav-buttons + var scrollCtrl = el.find('ion-content').controller('$ionicScroll'); + expect(scrollCtrl).toBeTruthy(); + expect(el.find('button[needs-scroll]').data('scrollCtrl')).toBe(scrollCtrl); + }); + + it('should not enter if button is destroyed before raf', function() { + var rafCb; + ionic.requestAnimationFrame = function(cb) { rafCb = cb; }; + var el = setup('left', '