diff --git a/src/typeahead/dataset.js b/src/typeahead/dataset.js index fce09c30..28fb78f9 100644 --- a/src/typeahead/dataset.js +++ b/src/typeahead/dataset.js @@ -269,8 +269,9 @@ var Dataset = (function() { // do not render the suggestions as they've become outdated if (!canceled && rendered < that.limit) { that.cancel = $.noop; + suggestions = suggestions.slice(0, that.limit - rendered); rendered += suggestions.length; - that._append(query, suggestions.slice(0, that.limit - rendered)); + that._append(query, suggestions); that.async && that.trigger('asyncReceived', query); } diff --git a/test/typeahead/dataset_spec.js b/test/typeahead/dataset_spec.js index e6560a50..c3021219 100644 --- a/test/typeahead/dataset_spec.js +++ b/test/typeahead/dataset_spec.js @@ -224,6 +224,20 @@ describe('Dataset', function() { }); }); + it('combines sync and async results', function() { + this.dataset.async = true; + this.dataset.limit = 10; + this.source.andCallFake(fakeGetWithAsyncSuggestions); + + this.dataset.update('woah'); + + waits(100); + + runs(function() { + expect(this.dataset.$el.find('.tt-suggestion')).toHaveLength(8); + }); + }); + it('should respect limit option in regard to async', function() { this.dataset.async = true; this.source.andCallFake(fakeGetWithAsyncSuggestions);