diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index a8d2d16ace..fb801d4871 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -487,6 +487,15 @@ describe('typeahead tests', function () { expect(element).toBeClosed(); }); + it('PR #3178, resolves #2999 - should not return property "length" of undefined for undefined matches', function () { + changeInputValueTo(element, 'c'); + expect(element).toBeClosed(); + + deferred.resolve(); + $scope.$digest(); + expect(element).toBeClosed(); + }); + }); describe('non-regressions tests', function () { @@ -777,7 +786,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(); diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index e47b6dae5e..63f196edfc 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) {