Skip to content

Commit

Permalink
fix(build): Add default for catch when try is defined and catch is not.
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanieJKS committed Jul 25, 2022
1 parent d970292 commit b1159e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/build/src/build/buildPages/buildBlock/buildEvents.js
Expand Up @@ -74,6 +74,9 @@ function buildEvents(block, pageContext) {
}". Received ${JSON.stringify(block.events[key].try)}`
);
}
if (type.isNone(block.events[key].catch)) {
block.events[key].catch = [];
}
if (!type.isArray(block.events[key].catch)) {
throw new Error(
`Catch actions must be an array at "${block.blockId}" in event "${key}.catch" on page "${
Expand Down
Expand Up @@ -146,14 +146,14 @@ test('block events actions as try array and catch not defined.', () => {
},
],
};
expect(() =>
buildPages({
components,
context,
})
).toThrow(
'Catch actions must be an array at "block_1" in event "onClick.catch" on page "page_1". Received undefined'
);
const res = buildPages({ components, context });
expect(get(res, 'pages.0.areas.content.blocks.0.events.onClick.try')).toEqual([
{
id: 'action_1',
type: 'Reset',
},
]);
expect(get(res, 'pages.0.areas.content.blocks.0.events.onClick.catch')).toEqual([]);
});

test('block events actions try not an array', () => {
Expand Down

0 comments on commit b1159e1

Please sign in to comment.