Skip to content

Commit 6b1a375

Browse files
Eunjae LeeHaroenv
Eunjae Lee
andauthoredJun 15, 2021
fix(clearRefinements): do not throw when widgetParams is not given (#4778)
Co-authored-by: Haroen Viaene <hello@haroen.me>
1 parent 1fdebf3 commit 6b1a375

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

‎src/connectors/clear-refinements/__tests__/connectClearRefinements-test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/clear-refin
2121
`);
2222
});
2323

24+
it('does not throw when widgetParams is not given', () => {
25+
const customClearRefinements = connectClearRefinements(() => {});
26+
27+
expect(() => {
28+
// @ts-expect-error widgetParams could be undefined
29+
// because it's supposed to work without any.
30+
customClearRefinements();
31+
}).not.toThrowError();
32+
});
33+
2434
it('throws with both `includedAttributes` and `excludedAttributes`', () => {
2535
const customClearRefinements = connectClearRefinements(() => {});
2636

‎src/connectors/clear-refinements/connectClearRefinements.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ const connectClearRefinements: ClearRefinementsConnector = function connectClear
9494
transformItems = (items => items) as TransformItems<string>,
9595
} = widgetParams || {};
9696

97-
if (widgetParams.includedAttributes && widgetParams.excludedAttributes) {
97+
if (
98+
widgetParams &&
99+
widgetParams.includedAttributes &&
100+
widgetParams.excludedAttributes
101+
) {
98102
throw new Error(
99103
withUsage(
100104
'The options `includedAttributes` and `excludedAttributes` cannot be used together.'

0 commit comments

Comments
 (0)
Please sign in to comment.