fix(build): Events with try defined should add default for catch.

This commit is contained in:
Gervwyk 2022-02-16 09:55:12 +02:00
parent 7a90f5b3ed
commit bb36b55d7c
2 changed files with 40 additions and 1 deletions

View File

@ -64,7 +64,10 @@ function buildEvents(block, pageContext) {
}". Received ${JSON.stringify(block.events[key].try)}`
);
}
if (!type.isArray(block.events[key].catch) && !type.isNone(block.events[key].catch)) {
if (type.isNone(block.events[key].catch)) {
block.events[key].catch = [];
}
if (!type.isArray(block.events[key].catch)) {
throw new Error(
`Catch events must be an array of actions at "${
block.blockId

View File

@ -120,6 +120,42 @@ test('block events actions as try catch arrays', async () => {
]);
});
test('block events actions as try array and catch not defined.', async () => {
const components = {
pages: [
{
id: 'page_1',
type: 'Container',
auth,
blocks: [
{
id: 'block_1',
type: 'Input',
events: {
onClick: {
try: [
{
id: 'action_1',
type: 'Reset',
},
],
},
},
},
],
},
],
};
const res = await 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', async () => {
const components = {
pages: [