Skip to content

Commit

Permalink
Throw err on update if suggestions are invalid type
Browse files Browse the repository at this point in the history
Resolves algolia#131
  • Loading branch information
ctinney committed Oct 9, 2018
1 parent adee769 commit 49656bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/autocomplete/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ _.mixin(Dataset.prototype, EventEmitter, {
.html(getSuggestionsHtml.apply(this, renderArgs))
.prepend(that.templates.header ? getHeaderHtml.apply(this, renderArgs) : null)
.append(that.templates.footer ? getFooterHtml.apply(this, renderArgs) : null);
} else if (suggestions && !Array.isArray(suggestions)) {
throw new Error('suggestions must be an array');
}

if (this.$menu) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/dataset_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ describe('Dataset', function() {
expect(this.dataset.getRoot()).toContainText('empty');
});

it('should throw an error if suggestions is not an array', function() {
expect(this.source.and.callFake(fakeGetNonArrayResults)).toThrow();
});

it('should set the aa-without class when no suggestions are available', function() {
var $menu = $('<div />');
this.dataset = new Dataset({
Expand Down Expand Up @@ -477,6 +481,10 @@ describe('Dataset', function() {
cb([{display: '4'}, {display: '5'}, {display: '6'}]);
}

function fakeGetNonArrayResults(query, cb) {
cb({});
}

function fakeGetWithSyncEmptyResults(query, cb) {
cb();
}
Expand Down

0 comments on commit 49656bf

Please sign in to comment.