Skip to content

Commit

Permalink
fix(core): dispose sets helper to null
Browse files Browse the repository at this point in the history
Without this change, if you dispose an instance and start it again, a search (not necessarily a request, since the cache isn't cleared) should be done again with a fresh state, and not the state of before the dispose

similar to #3399
  • Loading branch information
Haroenv committed Jan 21, 2019
1 parent 65e1a57 commit 5145956
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class InstantSearch extends EventEmitter {
dispose() {
this.removeWidgets(this.widgets);
this.started = false;
this.helper = null;
}

createURL(params) {
Expand Down
15 changes: 15 additions & 0 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,21 @@ describe('InstantSearch lifecycle', () => {
expect(helperSearchSpy).toHaveBeenCalledTimes(1);
expect(search.started).toBe(false);
});

it('should set the helper to `null`', () => {
search = new InstantSearch({
indexName,
searchClient: algoliasearch(appId, apiKey),
});

search.start();

expect(search.helper).not.toBe(null);

search.dispose();

expect(search.helper).toBe(null);
});
});

it('Allows to start without widgets', () => {
Expand Down

0 comments on commit 5145956

Please sign in to comment.