Skip to content

Commit 244425d

Browse files
sdwvitHaroenv
authored andcommitted
fix(clear): Avoid error when clear is called after destroy (#287)
* dataset-clear-npe-fix * rename test for clarity
1 parent 93c21b7 commit 244425d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/autocomplete/dataset.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,11 @@ _.mixin(Dataset.prototype, EventEmitter, {
256256
},
257257

258258
clear: function clear() {
259-
this.cancel();
260-
this.$el.empty();
261-
this.trigger('rendered', '');
259+
if (this.$el) {
260+
this.cancel();
261+
this.$el.empty();
262+
this.trigger('rendered', '');
263+
}
262264
},
263265

264266
isEmpty: function isEmpty() {

test/unit/dataset_spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ describe('Dataset', function() {
462462
this.dataset.clear();
463463
expect(spy).toHaveBeenCalled();
464464
});
465+
466+
it('should not throw if called right after destroy()', function() {
467+
this.source.and.callFake(fakeGetWithSyncResults);
468+
this.dataset.update('woah');
469+
this.dataset.destroy();
470+
this.dataset.clear();
471+
expect(this.dataset.getRoot()).toBeNull();
472+
});
465473
});
466474

467475
describe('#isEmpty', function() {

0 commit comments

Comments
 (0)