diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 68c751007f..8f2c7323c1 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -734,4 +734,33 @@ describe('typeahead tests', function () { }); }); + it('should not capture enter or tab until an item is focused', function () { + $scope.select_count = 0; + $scope.onSelect = function ($item, $model, $label) { + $scope.select_count = $scope.select_count + 1; + }; + var element = prepareInputEl('
'); + changeInputValueTo(element, 'b'); + + // enter key should not be captured when nothing is focused + triggerKeyDown(element, 13); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy(); + expect($scope.select_count).toEqual(0); + + // tab key should not be captured when nothing is focused + triggerKeyDown(element, 9); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeFalsy(); + expect($scope.select_count).toEqual(0); + + // down key should be captured and focus first element + triggerKeyDown(element, 40); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeTruthy(); + expect(element).toBeOpenWithActive(2, 0); + + // enter key should be captured now that something is focused + triggerKeyDown(element, 13); + expect($scope.keyDownEvent.isDefaultPrevented()).toBeTruthy(); + expect($scope.select_count).toEqual(1); + }); + });