fix: missing widgets (#3541)

This commit is contained in:
Erez Rokah 2020-04-05 16:46:26 +03:00 committed by GitHub
parent 76732f7208
commit 6933bf6ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 32 deletions

View File

@ -147,26 +147,4 @@ describe('registry', () => {
});
});
});
describe('getWidget', () => {
it('should throw on missing widget', () => {
const { getWidget } = require('../registry');
expect(() => getWidget('Unknown')).toThrow(
new Error(
`Could not find widget 'Unknown'. Please make sure the widget name is configured correctly or register it via 'registerwidget'.`,
),
);
});
it('should throw on missing widget and suggest lowercase name', () => {
const { getWidget, registerWidget } = require('../registry');
registerWidget('string', {});
expect(() => getWidget('String')).toThrow(
new Error(`Could not find widget 'String'. Did you mean 'string'?`),
);
});
});
});

View File

@ -113,16 +113,7 @@ export function registerWidget(name, control, preview) {
}
}
export function getWidget(name) {
const widget = registry.widgets[name];
if (!widget) {
const nameLowerCase = name.toLowerCase();
const hasLowerCase = !!registry.widgets[nameLowerCase];
const message = hasLowerCase
? `Could not find widget '${name}'. Did you mean '${nameLowerCase}'?`
: `Could not find widget '${name}'. Please make sure the widget name is configured correctly or register it via 'registerwidget'.`;
throw new Error(message);
}
return widget;
return registry.widgets[name];
}
export function getWidgets() {
return produce(Object.entries(registry.widgets), draft => {