Skip to content

Commit

Permalink
fix(queryRules): default options in CustomData widget
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Mar 14, 2019
1 parent 267a643 commit 01dac7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ describe('queryRuleCustomData', () => {
});

describe('Usage', () => {
test('throws container error without options', () => {
expect(() => {
// @ts-ignore
queryRuleCustomData();
}).toThrowErrorMatchingInlineSnapshot(`
"The \`container\` option is required.
See documentation: https://www.algolia.com/doc/api-reference/widgets/query-rule-custom-data/js/"
`);
});

test('throws container error with empty options', () => {
expect(() => {
// @ts-ignore
queryRuleCustomData({});
}).toThrowErrorMatchingInlineSnapshot(`
"The \`container\` option is required.
See documentation: https://www.algolia.com/doc/api-reference/widgets/query-rule-custom-data/js/"
`);
});

test('throws without container', () => {
expect(() => {
queryRuleCustomData({
Expand Down
12 changes: 7 additions & 5 deletions src/widgets/query-rule-custom-data/query-rule-custom-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ const renderer: QueryRulesRenderer<
);
};

const queryRuleCustomData: QueryRuleCustomData = ({
container,
templates: userTemplates = {},
transformItems = items => items,
}) => {
const queryRuleCustomData: QueryRuleCustomData = (
{
container,
templates: userTemplates = {},
transformItems = items => items,
} = {} as QueryRuleCustomDataWidgetParams
) => {
if (!container) {
throw new Error(withUsage('The `container` option is required.'));
}
Expand Down

0 comments on commit 01dac7f

Please sign in to comment.