Skip to content

Commit f60222d

Browse files
samoussbobylito
authored andcommitted
fix(connectRefinementList): throw error with usage (#2962)
* test(connectRefinementList): add a pattern for the error * fix(connectRefinementList): throw with the usage message * style(connectRefinementList): add spaces in the usage message
1 parent 7cc82f2 commit f60222d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/connectors/refinement-list/__tests__/connectRefinementList-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ describe('connectRefinementList', () => {
1414
};
1515

1616
it('throws on bad usage', () => {
17-
expect(connectRefinementList).toThrow();
17+
expect(connectRefinementList).toThrow(/Usage:/);
1818

1919
expect(() =>
2020
connectRefinementList({
2121
operator: 'and',
2222
})
23-
).toThrow();
23+
).toThrow(/Usage:/);
2424

25-
expect(() => connectRefinementList(() => {})()).toThrow();
25+
expect(() => connectRefinementList(() => {})()).toThrow(/Usage:/);
2626

2727
expect(() =>
2828
connectRefinementList(() => {})({
2929
operator: 'and',
3030
})
31-
).toThrow();
31+
).toThrow(/Usage:/);
3232

3333
expect(() =>
3434
connectRefinementList(() => {})({
3535
attributeName: 'company',
3636
operator: 'YUP',
3737
})
38-
).toThrow();
38+
).toThrow(/Usage:/);
3939
});
4040

4141
describe('options configuring the helper', () => {

src/connectors/refinement-list/connectRefinementList.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var customRefinementList = connectRefinementList(function render(params) {
1717
// widgetParams,
1818
// }
1919
});
20+
2021
search.addWidget(
2122
customRefinementList({
2223
attributeName,
@@ -27,15 +28,16 @@ search.addWidget(
2728
[ escapeFacetValues = false ]
2829
})
2930
);
31+
3032
Full documentation available at https://community.algolia.com/instantsearch.js/v2/connectors/connectRefinementList.html
3133
`;
3234

3335
export const checkUsage = ({
3436
attributeName,
3537
operator,
36-
usageMessage,
3738
showMoreLimit,
3839
limit,
40+
message,
3941
}) => {
4042
const noAttributeName = attributeName === undefined;
4143
const invalidOperator = !/^(and|or)$/.test(operator);
@@ -45,7 +47,7 @@ export const checkUsage = ({
4547
: false;
4648

4749
if (noAttributeName || invalidOperator || invalidShowMoreLimit) {
48-
throw new Error(usageMessage);
50+
throw new Error(message);
4951
}
5052
};
5153

@@ -159,7 +161,13 @@ export default function connectRefinementList(renderFn, unmountFn) {
159161
escapeFacetValues = false,
160162
} = widgetParams;
161163

162-
checkUsage({ attributeName, operator, usage, limit, showMoreLimit });
164+
checkUsage({
165+
message: usage,
166+
attributeName,
167+
operator,
168+
showMoreLimit,
169+
limit,
170+
});
163171

164172
const formatItems = ({ name: label, ...item }) => ({
165173
...item,

0 commit comments

Comments
 (0)