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

Commit

Permalink
fix(connectQueryRules): avoid to throw an error with undefined values (
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss authored May 14, 2019
1 parent 729a3a4 commit 1e18287
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ describe('connectQueryRules', () => {
expect(searchParameters.ruleContexts).toEqual(['initial-rule']);
});

it('does not throw an error with search state that contains `undefined` value', () => {
const props: QueryRulesProps = {
...defaultProps,
trackedFilters: {
price: values => values,
},
};

const searchState = {
refinementList: undefined,
};

expect(() => {
getSearchParameters(SearchParameters.make({}), props, searchState);
}).not.toThrow();
});

it('sets ruleContexts based on range', () => {
const priceSpy = jest.fn(values => values);
const props: QueryRulesProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ function getRefinements(
): TrackedFilterRefinement[] {
const refinements = Object.keys(searchState)
.filter(
widgetKey => typeof searchState[widgetKey][attribute] !== 'undefined'
widgetKey =>
searchState[widgetKey] !== undefined &&
searchState[widgetKey][attribute] !== undefined
)
.map(widgetKey => getWidgetRefinements(attribute, widgetKey, searchState))
.reduce((acc, current) => acc.concat(current), []); // flatten the refinements
Expand Down

0 comments on commit 1e18287

Please sign in to comment.