From f2106e10d21527cec7036b45925a70795bfeab56 Mon Sep 17 00:00:00 2001 From: Ara Hacobian Date: Sun, 11 Jan 2015 16:40:03 -0800 Subject: [PATCH 1/3] fix(typeahead): resolves property length of undefined error by checking value first #2999 --- src/typeahead/typeahead.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 8b080d615f..f2f968834b 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -131,7 +131,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //but we are interested only in responses that correspond to the current view value var onCurrentRequest = (inputValue === modelCtrl.$viewValue); if (onCurrentRequest && hasFocus) { - if (matches.length > 0) { + if (matches && matches.length > 0) { scope.activeIdx = focusFirst ? 0 : -1; scope.matches.length = 0; @@ -172,7 +172,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap //we need to propagate user's query so we can higlight matches scope.query = undefined; - //Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later + //Declare the timeout promise var outside the function scope so that stacked calls can be cancelled later var timeoutPromise; var scheduleSearchWithTimeout = function(inputValue) { From b44e42526d2c6fd727420a0633647439ecf18044 Mon Sep 17 00:00:00 2001 From: Ara Hacobian Date: Mon, 12 Jan 2015 13:09:04 -0800 Subject: [PATCH 2/3] fix(typeahead): resolves property length of undefined error, with test --- src/typeahead/test/typeahead.spec.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 8f2c7323c1..e39c10ea8d 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -453,7 +453,7 @@ describe('typeahead tests', function () { changeInputValueTo(element, 'c'); expect(element).toBeClosed(); - deferred.resolve(['good', 'stuff']); + deferred.resolve(['good1', 'stuff']); $scope.$digest(); expect(element).toBeOpenWithActive(2, 0); }); @@ -467,6 +467,14 @@ describe('typeahead tests', function () { expect(element).toBeClosed(); }); + it('PR #3178, resolves #2999 - should not return property "length" of undefined for matches', function () { + changeInputValueTo(element, 'c'); + expect(element).toBeClosed(); + + expect(deferred.resolve()).toEqual(undefined); + $scope.$digest(); + }); + }); describe('non-regressions tests', function () { @@ -741,7 +749,7 @@ describe('typeahead tests', function () { }; var element = prepareInputEl('
'); changeInputValueTo(element, 'b'); - + // enter key should not be captured when nothing is focused triggerKeyDown(element, 13); expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy(); From 9fefb69623a6cc53d387af748158560fb3ec4401 Mon Sep 17 00:00:00 2001 From: Ara Hacobian Date: Mon, 12 Jan 2015 15:16:31 -0800 Subject: [PATCH 3/3] test(typeahead): change back test params in promises good1 to good --- src/typeahead/test/typeahead.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index e39c10ea8d..5ba44e5b73 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -453,7 +453,7 @@ describe('typeahead tests', function () { changeInputValueTo(element, 'c'); expect(element).toBeClosed(); - deferred.resolve(['good1', 'stuff']); + deferred.resolve(['good', 'stuff']); $scope.$digest(); expect(element).toBeOpenWithActive(2, 0); });