Skip to content

Commit

Permalink
fix(clear): Avoid error when clear is called after destroy (#287)
Browse files Browse the repository at this point in the history
* dataset-clear-npe-fix

* rename test for clarity
  • Loading branch information
sdwvit authored and Haroenv committed Aug 28, 2019
1 parent 93c21b7 commit 244425d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/autocomplete/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ _.mixin(Dataset.prototype, EventEmitter, {
},

clear: function clear() {
this.cancel();
this.$el.empty();
this.trigger('rendered', '');
if (this.$el) {
this.cancel();
this.$el.empty();
this.trigger('rendered', '');
}
},

isEmpty: function isEmpty() {
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 @@ -462,6 +462,14 @@ describe('Dataset', function() {
this.dataset.clear();
expect(spy).toHaveBeenCalled();
});

it('should not throw if called right after destroy()', function() {
this.source.and.callFake(fakeGetWithSyncResults);
this.dataset.update('woah');
this.dataset.destroy();
this.dataset.clear();
expect(this.dataset.getRoot()).toBeNull();
});
});

describe('#isEmpty', function() {
Expand Down

0 comments on commit 244425d

Please sign in to comment.