Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(error): reset error if next query is successful (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthuret authored Jul 20, 2017
1 parent 1cc70a3 commit ff50a07
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ jest.mock('algoliasearch-helper/src/algoliasearch.helper.js', () => {
'algoliasearch-helper/src/algoliasearch.helper.js'
);
Helper.prototype._dispatchAlgoliaResponse = function(state) {
this.emit('error', { count: count++ }, state);
if (count > 3) {
this.emit('result', { count: count++ }, state);
} else {
this.emit('error', { count: count++ }, state);
}
};
Helper.prototype.searchForFacetValues = () => Promise.reject('error');
return Helper;
Expand Down Expand Up @@ -55,7 +59,7 @@ describe('createInstantSearchManager errors', () => {

const store = ism.store.getState();
expect(store.error).toEqual({ count: 0 });
expect(store.results).toBe(null);
expect(store.results).toEqual(null);

ism.widgetsManager.update();

Expand Down Expand Up @@ -113,5 +117,40 @@ describe('createInstantSearchManager errors', () => {
});
});
});

describe('reset error after a succesful query', () => {
it('on widget lifecyle', () => {
const ism = createInstantSearchManager({
indexName: 'index',
initialState: {},
searchParameters: {},
algoliaClient: client,
});

ism.widgetsManager.registerWidget({
getSearchParameters: params => params.setQuery('search'),
});

expect(ism.store.getState().error).toBe(null);

return Promise.resolve().then(() => {
jest.runAllTimers();

const store = ism.store.getState();
expect(store.error).toEqual({ count: 3 });
expect(store.results).toEqual(null);

ism.widgetsManager.update();

return Promise.resolve().then(() => {
jest.runAllTimers();

const store1 = ism.store.getState();
expect(store1.error).toEqual(null);
expect(store1.results).toEqual({ count: 4 });
});
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default function createInstantSearchManager({
...store.getState(),
metadata,
searching: true,
error: null,
});

// Since the `getSearchParameters` method of widgets also depends on props,
Expand All @@ -216,6 +217,7 @@ export default function createInstantSearchManager({
widgets: nextSearchState,
metadata,
searching: true,
error: null,
});

search();
Expand Down

0 comments on commit ff50a07

Please sign in to comment.