From 6da96a9877672cd32b22a466966d63507556c096 Mon Sep 17 00:00:00 2001 From: sonnym Date: Sat, 11 Jan 2014 10:38:39 -0500 Subject: [PATCH 1/2] test(tabs): failing test case for active functions This test case will cause the following error: Chrome 31.0 (Linux) tabs active should allow a function as an argument FAILED TypeError: undefined is not a function at Object.fn (/home/sonny/src/vendor/bootstrap/src/tabs/tabs.js:207:11) at Scope.$digest (/home/sonny/src/vendor/bootstrap/misc/test-lib/angular.js:11783:29) at Scope.$apply (/home/sonny/src/vendor/bootstrap/misc/test-lib/angular.js:12036:24) at generateElm (/home/sonny/src/vendor/bootstrap/src/tabs/test/tabs.spec.js:491:15) at null. (/home/sonny/src/vendor/bootstrap/src/tabs/test/tabs.spec.js:500:13) Chrome 31.0 (Linux): Executed 532 of 532 (1 FAILED) (22.178 secs / 21.353 secs) --- src/tabs/test/tabs.spec.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index 9bdccad374..e91a22568e 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -473,6 +473,36 @@ describe('tabs', function() { })); }); + describe('active', function() { + var generateElm; + + beforeEach(inject(function($compile, $rootScope) { + scope = $rootScope.$new(); + + generateElm = function(activeAttr) { + elm = $compile([ + '', + ' ', + ' heading', + ' ', + '' + ].join('\n'))(scope); + + scope.$apply(); + + return elm; + }; + })); + + it('should allow a function as an argument', function() { + scope.isActive = jasmine.createSpy(); + + elm = generateElm('isActive()'); + + expect(scope.isActive).toHaveBeenCalled(); + }); + }); + describe('disabled', function() { beforeEach(inject(function($compile, $rootScope) { scope = $rootScope.$new(); From 666c29aca65ad9818220ec06d36c4c9709f44418 Mon Sep 17 00:00:00 2001 From: sonnym Date: Sat, 11 Jan 2014 10:46:04 -0500 Subject: [PATCH 2/2] fix(tabs): allow functions to be pased into active by assigning angular.noop to setActive when getActive has an undefined assign property --- src/tabs/tabs.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tabs/tabs.js b/src/tabs/tabs.js index 0a368a2fb6..4f76440442 100644 --- a/src/tabs/tabs.js +++ b/src/tabs/tabs.js @@ -186,7 +186,8 @@ angular.module('ui.bootstrap.tabs', []) var getActive, setActive; if (attrs.active) { getActive = $parse(attrs.active); - setActive = getActive.assign; + setActive = getActive.assign || angular.noop; + scope.$parent.$watch(getActive, function updateActive(value, oldVal) { // Avoid re-initializing scope.active as it is already initialized // below. (watcher is called async during init with value ===